GORM Playground Link
https://github.com/go-gorm/playground/pull/1
Description
reproduce
package main
import (
"gorm.io/driver/mysql"
"gorm.io/gorm"
)
type User struct {
gorm.Model
Code string `gorm:"unique;comment:my code;"`
}
type User2 struct {
gorm.Model
Code string `gorm:"unique;comment:my code2;default:hello"`
}
func main() {
dsn := "root:@tcp(127.0.0.1:3306)/test?charset=utf8mb4&parseTime=True&loc=Local"
db, err := gorm.Open(mysql.Open(dsn), &gorm.Config{})
mustBeNil(err)
db.Migrator().DropTable(&User{})
err = db.AutoMigrate(&User{})
mustBeNil(err)
err = db.Table("users").AutoMigrate(&User2{})
mustBeNil(err)
}
func mustBeNil(err error) {
if err != nil {
panic(err)
}
}
After running this code, the final table schema will be:
***************************[ 1. row ]***************************
Table | users
Create Table | CREATE TABLE `users` (
`id` bigint unsigned NOT NULL AUTO_INCREMENT,
`created_at` datetime(3) DEFAULT NULL,
`updated_at` datetime(3) DEFAULT NULL,
`deleted_at` datetime(3) DEFAULT NULL,
`code` varchar(191) DEFAULT 'hello' COMMENT 'my code2',
PRIMARY KEY (`id`),
UNIQUE KEY `code` (`code`),
UNIQUE KEY `code_2` (`code`),
KEY `idx_users_deleted_at` (`deleted_at`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci
As you can see, there are 2 same unique index on the column code. I expected only 1 unique index on column code.
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 ✨