我只想停用我的 gorm 模型的 created_at 和 updated_at 字段,但無法在文檔中找到它。嘗試在數(shù)據(jù)庫(kù)中創(chuàng)建行時(shí)出現(xiàn)此錯(cuò)誤:Error 1054: Unknown column 'created_at' in 'field list'
1 回答

慕容3067478
TA貢獻(xiàn)1773條經(jīng)驗(yàn) 獲得超3個(gè)贊
created_at、id、updated_at、deleted_at 字段通過將 gorm.Model 嵌入到您的結(jié)構(gòu)中來嵌入到您的模型中。
所以,禁用它們而不是做
type Product struct {
gorm.Model
Code string
Price uint
}
做
type Product struct {
ID uint `gorm:"primarykey"`
Code string
Price uint
}
- 1 回答
- 0 關(guān)注
- 137 瀏覽
添加回答
舉報(bào)
0/150
提交
取消