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"}應該是無效的
1 回答

12345678_0001
TA貢獻1802條經驗 獲得超5個贊
為兩個字段指定相同的索引名稱。
type ABC struct { ID uint Abc int `gorm:"uniqueIndex:abc_bcd_uniq"` Bcd string `gorm:"uniqueIndex:abc_bcd_uniq"`}
請參閱GORM 文檔中的復合索引。
- 1 回答
- 0 關注
- 106 瀏覽
添加回答
舉報
0/150
提交
取消