我的结构体节选

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"

Comment From: github-actions[bot]

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.io ✨ Search Before Asking