In GORM, AutoMigration()
also gives the NOT NULL attribute on the database side?
Thanks in advance
The answer is: No
So if you don't define not null
(using the gorm field tag) to that specific field, gorm will not add the not null
constraint to the field on the database side. Except for primary keys. By default, pk will be defined as a not null
field.
How to define a field as not null
in gorm:
type User struct { ... Email string `gorm:"not null"` // NOT NULL ... }
For more information, please refer to gorm official documentation: Field tags p>
The above is the detailed content of Does AutoMigration() also give NOT NULL attribute on database side?. For more information, please follow other related articles on the PHP Chinese website!