如何定义struct来为Gorm中的Gorm指定多列唯一索引?

如:

type Something struct {
    gorm.Model
    First  string `sql:"unique_index:unique_index_with_second"`
    Second string `sql:"unique_index:unique_index_with_first"`
}

最佳答案

您是否要创建一个表,以使“第一”和“第二”的组合是唯一的?

这应该工作:

type Something struct {
    ID uint
    gorm.Model
    First  string `gorm:"primary_key"`
    Second string `gorm:"primary_key"`
}

关于go - 如何为Gorm指定具有多列唯一索引的结构?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/30831316/

10-12 00:16
查看更多