[go][beego] needs a primary key field, default is to use 'id' if not set
在beego中,新建model时不声明主键会在编译时出错,出现如标题提示。 解决方法是将id后添加声明即可。 报错前的代码: type Relationship struct { Id string User string RepostUser string AtUser string RepostLevel string AtLevel string Relationships *Relationship `orm:"rel(fk)"` } 更改后的代码: type Relationship struct { Id string `orm:"column(uid);pk"` // 设置主键 User string RepostUser string AtUser string RepostLevel string AtLevel string Relationships *Relationship `orm:"rel(fk)"` } 问题解决! 文章来源: [go][beego] needs a primary key field, default is to use 'id' if not set