为了账号安全,请及时绑定邮箱和手机立即绑定

GORM 嵌入式结构未迁移到 SQL

GORM 嵌入式结构未迁移到 SQL

Go
繁华开满天机 2022-09-26 19:57:10
我在GORM中声明以下模型:type DBModel struct {    ID        uint       `gorm:"primaryKey"`    CreatedAt *time.Time `json:"_"`    UpdatedAt *time.Time `json:"_"`    DeletedAt *time.Time `json:"_"`    ClientID  uint       `gorm:"not_null"`}type Address struct {    address string    city    string    state   string    pincode int    country string}type Office struct {    DBModel        DBModel `gorm:"embedded"`    Address        Address `gorm:"embedded"`    Name           string}跑步时func Init(db *gorm.DB) {    DB = db    DB.AutoMigrate(&models.Office{})}正在迁移的 Office 表包含以下字段:idcreated_atupdated_atdeleted_atclient_idname为什么地址结构未嵌入?
查看完整描述

1 回答

?
弑天下

TA贡献1818条经验 获得超8个赞

好的,明白了。


地址结构的字段应为导出字段。字段必须以大写字母开头才能导出。


更改地址结构可以完成以下工作:


type Address struct {

    Address string

    City    string

    State   string

    Pincode int

    Country string

}


查看完整回答
反对 回复 2022-09-26
  • 1 回答
  • 0 关注
  • 72 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号