need to define a valid foreign key for
来源:1-13 商品分类的列表接口 - 2
游泳的石头
2021-05-07 11:01:08
invalid field found for struct golearn/goods_srv/model.Category's field SubCategory, need to define a valid foreign key for relations or it need to implement the Valuer/Scanner interface
请问老师,这个怎么处理?
1回答
bobby
2021-05-08
type Category struct{
BaseModel
Name string `gorm:"type:varchar(20);not null" json:"name"`
ParentCategoryID int32 `json:"parent"`
ParentCategory *Category `json:"-"`
SubCategory []*Category `gorm:"foreignKey:ParentCategoryID;references:ID" json:"sub_category"`
Level int32 `gorm:"type:int;not null;default:1" json:"level"`
IsTab bool `gorm:"default:false;not null" json:"is_tab"`
}
你拷贝这个代码看看是否和你的代码不一致
相似问题