example: https://github.com/go-gorm/playground/pull/782

package main

type Order struct {
    ID      uint64 `gorm:"column:id;type:bigint unsigned;primaryKey;autoIncrement:true"`
    UserID  uint64 `gorm:"column:user_id;type:bigint unsigned;not null;uniqueIndex:unique_user,priority:1;"`
    Product string `gorm:"column:product;type:varchar(63);not null;"`
}

type User struct {
    ID      uint64 `gorm:"column:id;type:bigint unsigned;primaryKey;autoIncrement:true"`
    UserID  uint64 `gorm:"column:user_id;type:bigint unsigned;not null;uniqueIndex:unique_user,priority:1;"`
    Name string `gorm:"column:product;type:varchar(63);not null;"`
}

func main() {
    db, err := gorm.Open(sqlite.Open("gormtest.db"), &gorm.Config{})
    if err != nil {
        panic(errors.Wrapf(err, "failed to connect to database"))
    }

db.AutoMigrate(&Order{},&User{})
}

SQLERROR: SQL error or missing database (index unique_user already exists)

sqlite驱动需要在生成索引名称时候自动添加表前缀作为索引名称区别

Comment From: lazychanger

https://github.com/go-gorm/sqlite/blob/02b8e0623276590f0a11475cbdd4fcb883336978/migrator.go#L255-L257

这里

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