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

MUL unique index always causes field migration #5951

Closed
Nomango opened this issue Dec 30, 2022 · 4 comments · Fixed by #5974
Closed

MUL unique index always causes field migration #5951

Nomango opened this issue Dec 30, 2022 · 4 comments · Fixed by #5974
Assignees
Labels

Comments

@Nomango
Copy link
Contributor

Nomango commented Dec 30, 2022

GORM Playground Link

No time to make it for now.

Description

Similar to #5950, the reason is field migration is checking field.Unique in this line:

if unique, ok := columnType.Unique(); ok && unique != field.Unique {

For mysql environment, columnType.Unique is only true when column_key is equal to UNI.

https://github.com/go-gorm/mysql/blob/7746e77af41571f61e6154eccd46dce1c6da0a1d/migrator.go#L222

But composite indexes' column_key is MUL. Therefore it always causes field migration.

@github-actions github-actions bot added the type:missing reproduction steps missing reproduction steps label Dec 30, 2022
@github-actions
Copy link

The issue has been automatically marked as stale as it missing playground pull request link, which is important to help others understand your issue effectively and make sure the issue hasn't been fixed on latest master, checkout https://github.com/go-gorm/playground for details. it will be closed in 30 days if no further activity occurs. if you are asking question, please use the Question template, most likely your question already answered https://github.com/go-gorm/gorm/issues or described in the document https://gorm.ioSearch Before Asking

@Nomango
Copy link
Contributor Author

Nomango commented Jan 3, 2023

It seems that it cannot be reproduced.

@Nomango Nomango closed this as completed Jan 3, 2023
@Nomango
Copy link
Contributor Author

Nomango commented Jan 11, 2023

Since the merger last week this issue has come up again.

Should field.Unique be true if the field has a MUL unique index?

@Nomango Nomango reopened this Jan 11, 2023
@Nomango Nomango changed the title Composite indexes always causes field migration MUL unique index always causes field migration Jan 11, 2023
@github-actions
Copy link

The issue has been automatically marked as stale as it missing playground pull request link, which is important to help others understand your issue effectively and make sure the issue hasn't been fixed on latest master, checkout https://github.com/go-gorm/playground for details. it will be closed in 30 days if no further activity occurs. if you are asking question, please use the Question template, most likely your question already answered https://github.com/go-gorm/gorm/issues or described in the document https://gorm.ioSearch Before Asking

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

Successfully merging a pull request may close this issue.

2 participants