如何在Gorm中指定唯一的索引?
type ABC struct {
ID uint
Abc int `gorm:"unidqueIndex;
Bcd string
}
我想要字段abc
和bcd
是唯一在一起
{abc:1,bcd:“ hello”} {abc:1,bcd:“ hi”} < /code>应该有效,但
{ABC:1,BCD:“ Hello”} {ABC:1,BCD:“ Hello”}
应该无效
type ABC struct {
ID uint
Abc int `gorm:"unidqueIndex;
Bcd string
}
I want Field Abc
and Bcd
to be unique together
{Abc: 1, Bcd: "hello"} {Abc: 1, Bcd: "hi"}
should be valid but
{Abc: 1, Bcd: "hello"} {Abc: 1, Bcd: "hello"}
should be invalid
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
给两个字段都有相同的索引名称。
参见 gorm doc中的复合索引。
Give both fields the same index name.
See composite indexes in the GORM docs.