将当前时间的默认值设置为 Ecto 迁移中的日期时间列

Setting a default value of the current time to a datetime column in an Ecto migration

我正在寻找与此类似的东西 SQL。

column_name my_timestamp_column NOT NULL DEFAULT CURRENT_TIMESTAMP

请注意,我要求列的名称是可指定的,因此 timestamps 宏不适用。

您可以像这样在迁移中执行SQL

def change do
  execute("ALTER TABLE some_table ADD some_column timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP")
end