0
点赞
收藏
分享

微信扫一扫

Go踩过的坑之gorm外键关联字段null值无法插入

颜路在路上 2021-09-19 阅读 26
GoGolang ...

Go踩过的坑之gorm外键关联字段无法插入

先知

业务重现

type School struct{
    SchId    int     `json:"SchId"      gorm:"column:SchId;type:int;size:11;not null;primary_key;AUTO_INCREMENT;"`
    Name      string  `json:"Name"        gorm:"column:Name;type:varchar;size:500;not null;"`
}
type Stu struct{
    StuId    int     `json:"SchId"      gorm:"column:SchId;type:int;size:11;not null;primary_key;AUTO_INCREMENT;"`
    Name      string  `json:"Name"        gorm:"column:Name;type:varchar;size:500;not null;"`
    SchId    int     `json:"SchId"      gorm:"column:SchId;type:int;size:11;"`
}
func main() {
    addModel := model.Stu{
        Name:   "xj",
    }
    err:=dao.insert(&addModel)
    if err.Error!=nil{
        fmt.Println(err)
    }
}
举报

相关推荐

0 条评论