我在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
}
- 1 回答
- 0 关注
- 72 浏览
添加回答
举报
0/150
提交
取消