GORM Playground Link

https://github.com/go-gorm/playground/pull/512

Description

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.

Comment From: a631807682

It is a bug, are you interested in creating a PR to fix it?

Comment From: Joaolfc0

This bug is still happening for me

Comment From: a631807682

https://github.com/go-gorm/gorm.io/pull/782