admin管理员组

文章数量:1636810

 解决方法:

type User struct {
  gorm.Model
  Name      string
  SchoolId int
  School School `gorm:"foreignKey:SchoolId"` // 使用SchoolId作为外键
}

type School struct {
  ID   int
  Class string
}

如果还报错修改为:

type User struct {
  gorm.Model
  Name      string
  School School `gorm:"association_foreignkey:ID"` // School的ID作为关联外键
}

type School struct {
  ID   int
  Class string
}

这样就不会报错了!

本文标签: 报错初始化解决方法defineValid