GORM Playground Link
https://github.com/go-gorm/playground/pull/1
Description
version:1.25.10 question: It can only be executed when the table is created for the first time. If it is executed again, as long as there is a unique index in the table, it will prompt that an undefined index cannot be deleted. -- 只有第一次创建表的时候可以执行,再次执行,只要表有唯一索引,就会提示无法删除一个未定义的索引 error:Error 1091 (42000): Can't DROP 'uni_sys_users_user_name'; check that column/key exists
UserName string gorm:"size:50;column:user_name;comment:登录名称;uniqueIndex:idx_user_name;" json:"userName" // 登录名称
Comment From: Seo-yul
I also faced same error. so, I explicitly named the table and it worked.
Add model code.
gorm:"table:YOUR_TABLE_NAME"
and modify code AS-IS
DB.Table("YOUR_TABLE_NAME").AutoMigrate(&model.YOUR_MODEL{});
TO-BE
# DB is *gorm.DB
DB.AutoMigrate(&model.YOUR_MODEL{});
Comment From: aixj1984
I also faced same error. so, I explicitly named the table and it worked.
Add model code.
gorm:"table:YOUR_TABLE_NAME"and modify code AS-IS
DB.Table("YOUR_TABLE_NAME").AutoMigrate(&model.YOUR_MODEL{});TO-BE
```
DB is *gorm.DB
DB.AutoMigrate(&model.YOUR_MODEL{}); ```
how to use the code block?
Add model code. gorm:"table:YOUR_TABLE_NAME"
Comment From: aixj1984
I define mode use this.
``
type YOUR_MODEL struct {
// 字段定义
ID uintgorm:"primaryKey"Name stringgorm:"size:255"`
}
// 显式指定表名 func (YOUR_MODEL) TableName() string { return "YOUR_TABLE_NAME" }`
Comment From: aixj1984
https://github.com/go-gorm/gorm/issues/7010