GORM 嵌入式结构未迁移到 SQL

我在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 表包含以下字段:


id

created_at

updated_at

deleted_at

client_id

name

为什么地址结构未嵌入?


繁华开满天机
浏览 109回答 1
1回答

弑天下

好的,明白了。地址结构的字段应为导出字段。字段必须以大写字母开头才能导出。更改地址结构可以完成以下工作:type Address struct {    Address string    City    string    State   string    Pincode int    Country string}
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Go