如何在特定于结构的列上设置唯一性。名字
type User struct {
ID int64 `orm:"size(100)", pk`
Lastname string `orm:"size(100)"`
Firstname string `orm:"size(100)"`
Role string `orm:"size(100)"`
Created time.Time `orm:"size(100)"`
Updated time.Time `orm:"size(100)"`
}
我正在使用 "github.com/astaxie/beego/orm"
最佳答案
根据documentation ,您只需在标签中添加“唯一”一词即可:
Add unique key for one field
Name string `orm:"unique"`
要组合标签,您必须使用分号作为记录 here .例如:
Firstname string orm:"unique;size(100)"
关于go - 如何在struct Beego中设置unique,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56274234/