You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It's not possible to change not nullable field to nullable.
type Test struct {
gorm.Model
SomeStr string `gorm:"type:VARCHAR(15);NOT NULL"`
}
After AutoMigrate is run, some_str field on DB is not nullable, then changing struct to this:
type Test struct {
gorm.Model
SomeStr string `gorm:"type:VARCHAR(15);default:NULL"`
}
and running AutoMigrate again, field remains not nullable.
I believe problem is here: https://github.com/go-gorm/gorm/blob/master/migrator/migrator.go#L439
both nullable (actual state on DB) and field.NotNull (new value) are false, meaning it's only possible to change from nullable to not nullable. I don't know if it's done on purpose.
The text was updated successfully, but these errors were encountered:
GORM Playground Link
go-gorm/playground#512
Description
It's not possible to change not nullable field to nullable.
After
AutoMigrate
is run,some_str
field on DB is not nullable, then changing struct to this:and running
AutoMigrate
again, field remains not nullable.I believe problem is here: https://github.com/go-gorm/gorm/blob/master/migrator/migrator.go#L439
both
nullable
(actual state on DB) andfield.NotNull
(new value) arefalse
, meaning it's only possible to change from nullable to not nullable. I don't know if it's done on purpose.The text was updated successfully, but these errors were encountered: