Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automigration NOT NULL to DEFAULT NULL not working #5643

Closed
pjarmalavicius opened this issue Aug 25, 2022 · 3 comments
Closed

Automigration NOT NULL to DEFAULT NULL not working #5643

pjarmalavicius opened this issue Aug 25, 2022 · 3 comments
Assignees
Labels
type:with reproduction steps with reproduction steps

Comments

@pjarmalavicius
Copy link

GORM Playground Link

go-gorm/playground#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.

@a631807682
Copy link
Member

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

@Joaolfc0
Copy link

This bug is still happening for me

@a631807682
Copy link
Member

go-gorm/gorm.io#782

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:with reproduction steps with reproduction steps
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants