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

AutoMigrate重复创建唯一索引? #5715

Closed
congjunhua opened this issue Sep 24, 2022 · 4 comments
Closed

AutoMigrate重复创建唯一索引? #5715

congjunhua opened this issue Sep 24, 2022 · 4 comments
Assignees
Labels
type:question general questions

Comments

@congjunhua
Copy link

congjunhua commented Sep 24, 2022

Your Question

type User struct {
    gorm.Model
    PublicID uint `gorm:"type:char(10);not null;unique"`
}

db.AutoMigrate(&User{})

为什么这样子写法每次重新运行程序时MySQL都会增加一个键和索引呢?

-- key
public_id
public_id_1
public_id_2
public_id_3
...

-- unique
public_id
public_id_1
public_id_2
public_id_3
...

直到报Error 1069: Too many keys specified; max 64 keys allowed错误。

@congjunhua congjunhua added the type:question general questions label Sep 24, 2022
@github-actions github-actions bot added type:missing reproduction steps missing reproduction steps and removed type:question general questions labels Sep 24, 2022
@github-actions
Copy link

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.ioSearch Before Asking

@CharellKing
Copy link

老铁,我也遇到这样的问题,你是怎么解决的

@congjunhua
Copy link
Author

老铁,我也遇到这样的问题,你是怎么解决的

unique 换成 uniqueIndex

@a631807682
Copy link
Member

#6381 (comment)

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

No branches or pull requests

4 participants