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.
GORM Playground Link
https://github.com/go-gorm/playground/pull/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 bothnullable
(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.