有没有办法停用 created_at 和 updated_at 的 us?
Is there a way to deactivate the us of created_at and updated_at?
我只想停用我的 gorm 模型的 created_at 和 updated_at 字段,在文档中找不到它。
尝试在数据库中创建行时出现此错误:
Error 1054: Unknown column 'created_at' in 'field list'
通过将 gorm.Model 嵌入到您的结构中,created_at、id、updated_at、deleted_at 字段被嵌入到您的模型中。
所以,禁用它们而不是做
type Product struct {
gorm.Model
Code string
Price uint
}
做
type Product struct {
ID uint `gorm:"primarykey"`
Code string
Price uint
}
我只想停用我的 gorm 模型的 created_at 和 updated_at 字段,在文档中找不到它。
尝试在数据库中创建行时出现此错误:
Error 1054: Unknown column 'created_at' in 'field list'
通过将 gorm.Model 嵌入到您的结构中,created_at、id、updated_at、deleted_at 字段被嵌入到您的模型中。
所以,禁用它们而不是做
type Product struct {
gorm.Model
Code string
Price uint
}
做
type Product struct {
ID uint `gorm:"primarykey"`
Code string
Price uint
}