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

DB.AutoMigrate migrates associated tables #5913

Closed
Nomango opened this issue Dec 8, 2022 · 1 comment · Fixed by #5946
Closed

DB.AutoMigrate migrates associated tables #5913

Nomango opened this issue Dec 8, 2022 · 1 comment · Fixed by #5946
Assignees
Labels
type:with reproduction steps with reproduction steps

Comments

@Nomango
Copy link
Contributor

Nomango commented Dec 8, 2022

GORM Playground Link

go-gorm/playground#549

Description

DB.AutoMigrate automatically migrates associated tables, which is unexpected.

This led to an intolerable production environment accident. When I published a new feature to production it modified many existing tables.

If this is a feature but not a bug, there should be a configuration to disable it.

Example

There are two tables, T2 is associated with T1, where T1 has a content field of type varchar(xx)

type T1 struct {
	gorm.Model
	Content string
}

type T2 struct {
	gorm.Model
	T1ID uint
	T1   *T1
}

When I run the following codes

DB.AutoMigrate(&T2{})

The content field type of t1 is changed to longtext

@github-actions github-actions bot added the type:with reproduction steps with reproduction steps label Dec 8, 2022
@Nomango
Copy link
Contributor Author

Nomango commented Dec 27, 2022

gorm:"-:migration" is not working either.

E.g.

type T1 struct {
	gorm.Model
	Content string
}

type T2 struct {
	gorm.Model
	T1ID uint
	T1   *T1 `gorm:"-:migration"`
}

DB.AutoMigrate(&T2{})

T1 is always modified after migrating T2.

Is this as expected?

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.

2 participants