【问题标题】:Yii2 update column on update, and default value current timestamp in postgresYii2 更新时更新列,以及 postgres 中的默认值当前时间戳
【发布时间】:2020-02-11 02:58:23
【问题描述】:

在 yii2 迁移文件中我创建了两列

'updated_at' => $this->integer()->defaultValue('CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP'),
'created_at' => $this->integer()->defaultValue('CURRENT_TIMESTAMP')

但这在 MYSQL 中有效,在 PostgreSQL 中无效?

如何在更新行时创建列并更新timestamp 列,并在创建行时设置默认timestamp

【问题讨论】:

    标签: postgresql yii2


    【解决方案1】:

    如果您想要不依赖于使用过的 DBMS 的解决方案,您可以使用 yii\behaviors\TimestampBehavior

    否则您必须使用触发器来设置更新时的当前时间戳。有关更多信息,请参阅此问题Update timestamp when row is updated in PostgreSQL

    【讨论】:

      猜你喜欢
      • 2021-07-26
      • 1970-01-01
      • 2019-05-06
      • 1970-01-01
      • 1970-01-01
      • 2022-11-30
      • 1970-01-01
      • 1970-01-01
      • 2018-12-26
      相关资源
      最近更新 更多