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

add uniqueIndex for AutoMigrate #733

Closed
wants to merge 1 commit into from
Closed

Conversation

ocean-gao
Copy link

Explain your user case and expected results

type User struct {
	EnglishName string `json:"englishName" gorm:"uniqueIndex:idx_english_name;column:englishName;type:varchar(100);comment:英文名;"`
}

执行

DB.AutoMigrate(&User{})

的时候,初次执行正常,再次执行报错:

ALTER TABLE t_users DROP FOREIGN KEY uni_t_users_english_name
AutoMigrate for table faild. err:Error 1091 (42000): Can't DROP 'uni_t_users_english_name'; check that column/key exists

实际上是没有这个外键的,但依然会drop这个外键。

预期结果:

判断此外键是否存在,存在再去执行 Drop 方法。

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

Successfully merging this pull request may close these issues.

1 participant