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
Unnecessarily unique indexes created when running AutoMigrate
#6224
Comments
This error is caused by the lack of distinction between Unique and UniqueIndex in schema.Filed and gorm.ColumnType. |
When So the solution is either checking if the unique index is already created before running the
|
Because the migration needs to compare unique and unique index, they are also part of the migration. It is complicated for each driver to achieve such a comparison, and it is not conducive to expansion and maintenance, so the best way is to complete this repeated comparison by gorm operation, unless it cannot be done. |
I have the same problem. Any update on this? If you need any help, I can do some coding. |
GORM Playground Link
go-gorm/playground#589
Description
Model
User
has only one fieldName
, withuniqueIndex
tag. First time I runAutoMigrate
, GORM will create two unique indexes calledidx_users_name
andname
. Then every time I runAutoMigrate
, GORM will create a new unique index calledname_2
,name_3
and so on.If I use
uniqueIndex:i_u_name
to specify the name of the unique index, the first run would still createi_u_name
andname
indexes, and the following runs would still createname_2
,name_3
indexes.The text was updated successfully, but these errors were encountered: