为了账号安全,请及时绑定邮箱和手机立即绑定

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

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

Go
慕容森 2023-01-03 11:20:18
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 文档中的复合索引


查看完整回答
反对 回复 2023-01-03
  • 1 回答
  • 0 关注
  • 64 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信