Closed ilmari-h closed 1 month ago
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.io ✨ Search Before Asking ✨
Issue:
Two indices created when using syntax
uniqueIndex:custom_index_name
Expected result
Using the uniqueIndex with a custom name for the index creates just one unique index with the given name
Actual result
Both the default index (that would be created without the given name) and the named index are created:
idx_tablename_columnname
custom_index_name
Description
I was unable to make go-playground run (there's an active issue for that) but this issue is easily reproduced with e.g. the following go code
This creates two indexes in the PostgreSQL database:
idx_users_name
and the index I wanted to createuni_name_index_gorm
.If I use just the tag
gorm:"uniqueIndex"
without a given name, only the first indexidx_users_name
is createdHowever, if I have the
uniqueIndex:custom_index_name
tag with the same name applied to multiple columns, then only that one named index gets created, so in that use-case it works as intended.