不使用gorm推送空结构
我想用Gorm推送传感器结构。但传感器结构并不总是在数据库中显示天气或规格1不使用gorm推送空结构,go,struct,go-gorm,Go,Struct,Go Gorm,我想用Gorm推送传感器结构。但传感器结构并不总是在数据库中显示天气或规格1 type Weather struct { temp int `gorm:"type:int(11);null"` } type Data struct { index int `gorm:"type:int(11);null"` id int `gorm:"type:int(11);null"` } type OtherSpec struct { otherSpec int
type Weather struct {
temp int `gorm:"type:int(11);null"`
}
type Data struct {
index int `gorm:"type:int(11);null"`
id int `gorm:"type:int(11);null"`
}
type OtherSpec struct {
otherSpec int `gorm:"type:int(11);null"`
}
type Sensor struct {
*Data
*Weather
*OtherSpec
}
我的目标是推动传感器结构,即使spec1或天气不存在。
但当我做这些事情时,gorm说:
Error 1054: Unknown column 'temp' in 'field list'
例如,如果天气不是必需的,db没有这些字段,我如何对gorm说不要推天气。存在
gorm:“-”
忽略一个字段,但我不想总是忽略他。当结构没有嵌入时它能工作吗?例如,从Weather复制温度并粘贴到*传感器中的位置,然后尝试哦,并确保该列存在于数据库中。如果该列存在于数据库中,则该操作有效。但是所有的数据库都没有天气栏。我想使用一个环境变量来禁用weather struct轻松推送。我不想有x结构的不同:一个有Spec1,另一个有Spec1,没有天气。。。