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

MySQL-描述表的结构体,给其属性添加autoIncrement 执行AutoMigrate()方法 数据库会新建一个索引 #6780

Closed
Sherlock-HJ opened this issue Jan 5, 2024 · 5 comments
Assignees
Labels

Comments

@Sherlock-HJ
Copy link

我的结构体节选

type Site1 struct {
ID string gorm:"size:25"
SerialNo uint32 gorm:"column:serialNo;not null;uniqueIndex:serialNo;autoIncrement"
Domain string gorm:"size:30;not null;uniqueIndex:domain;comment:一级域名"
Domain2 string gorm:"size:20;not null;uniqueIndex:domain;comment:二级域名"
}

因为我的表已经存在了所以没有使用gorm.Model
我执行db.AutoMigrate(&models.Site1{})后 结果如下表,多了个serialNo_2。将autoIncrement删除 问题消失

截屏2024-01-05 17 54 48

另外我还试了其它几种情况都会创建多个,执行一次db.AutoMigrate(&models.Site1{})创建一个类似,serialNo_3,serialNo_4,serialNo_5 ...
其它情况如下
SerialNo uint32 gorm:"column:serialNo;not null;unique;autoIncrement"
SerialNo uint32 gorm:"column:serialNo;not null;unique:serialNo;autoIncrement"

@Sherlock-HJ Sherlock-HJ added the type:question general questions label Jan 5, 2024
@github-actions github-actions bot added type:missing reproduction steps missing reproduction steps and removed type:question general questions labels Jan 5, 2024
Copy link

github-actions bot commented Jan 5, 2024

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

@shenxianghong
Copy link

解决了吗

Copy link

github-actions bot commented Jan 9, 2024

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

@Sherlock-HJ
Copy link
Author

解决了吗

没有,先这么用着

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

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Feb 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants