如何在 gorm 中指定唯一的一起索引?

type ABC struct {

ID uint

 Abc int `gorm:"unidqueIndex;

Bcd string

}

我想要 FieldAbc和Bcd一起变得独一无二


{Abc: 1, Bcd: "hello"} {Abc: 1, Bcd: "hi"}应该是有效的但是


{Abc: 1, Bcd: "hello"} {Abc: 1, Bcd: "hello"}应该是无效的


慕容森
浏览 67回答 1
1回答

12345678_0001

为两个字段指定相同的索引名称。type ABC struct {  ID uint  Abc int `gorm:"uniqueIndex:abc_bcd_uniq"`  Bcd string `gorm:"uniqueIndex:abc_bcd_uniq"`}请参阅GORM 文档中的复合索引。
打开App,查看更多内容
随时随地看视频慕课网APP