-
-
Notifications
You must be signed in to change notification settings - Fork 4k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Automigrate error caused by indexes while using dynamic table name #4752
Comments
@neeroz hello,this may be a problem with sqlite,It does not support indexes with the same name. |
@neeroz thanks,this is bug and will be fixed later. |
Sorry, I tried to solve this problem, but it led to more mistakes, at last, I have no way... (I should make a pull request after full testing) |
because the problem happen in |
GORM Playground Link
go-gorm/playground#386
Description
I am trying to migrate tables using dynamic table name. All these tables have different name but the same schema. I am using scopes to generate the dynamic table name.
The tables are created with the dynamic table name but the indexes are not created as it should.
Struct
type NewUser struct {
gorm.Model
Name string
gorm:"index"
City string
gorm:"index"
Table string
gorm:"-"
}
tableNameFormat
newuser_%x
tableName := []string{"a","b","c"}
table created successfully
newuser_a
,newuser_b
,newuser_c
When using scopes to generate the dynamic table name, the indexes are formatted as
idx_new_users_name
for all the tables and thus error ->Failed, got error: index idx_new_users_name already exists
To Reproduce Error:
./test.sh
Expected Output:
While doing migration, the tables with dynamic names should be created along with its indexes.
The text was updated successfully, but these errors were encountered: