【问题标题】:Is there a way to deactivate the us of created_at and updated_at?有没有办法停用 created_at 和 updated_at 的 us?
【发布时间】:2020-12-15 19:48:43
【问题描述】:

我只想停用我的 gorm 模型的 created_at 和 updated_at 字段,在文档中找不到。

尝试在数据库中创建行时出现此错误:

Error 1054: Unknown column 'created_at' in 'field list'

【问题讨论】:

    标签: go go-gorm


    【解决方案1】:

    created_at、id、updated_at、deleted_at 字段通过将 gorm.Model 嵌入到您的结构中来嵌入到您的模型中。

    所以,禁用它们而不是这样做

    type Product struct {
      gorm.Model
      Code  string
      Price uint
    }
    

    type Product struct {
      ID    uint `gorm:"primarykey"`
      Code  string
      Price uint
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-11-04
      • 2012-09-03
      • 2017-05-26
      • 1970-01-01
      • 2020-06-02
      • 2018-09-16
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多