1 回答

TA貢獻(xiàn)1807條經(jīng)驗(yàn) 獲得超9個(gè)贊
因?yàn)樵撝礷alse將被讀取為空值。因?yàn)榭罩的臄?shù)據(jù)將更改為默認(rèn)值 (TRUE)
您必須將結(jié)構(gòu)更改為這樣
type Car struct {
ID uint64
Required *bool `pg:"required,notnull,default:true"`
Name string `pg:"name"`
}
并像這樣定義結(jié)構(gòu)
required := false
car = Car{Name:"Name", Required: &required}
或者您也可以sql.NullBool在結(jié)構(gòu)中使用數(shù)據(jù)類型
type Car struct {
ID uint64
Required sql.NullBool `pg:"required,notnull,default:true"`
Name string `pg:"name"`
}
car = Car{Name:"Name", Required: sql.NullBool{Bool: false, Valid: true}}
- 1 回答
- 0 關(guān)注
- 132 瀏覽
添加回答
舉報(bào)