简体   繁体   中英

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

I'm looking for something similar to this SQL.

column_name my_timestamp_column NOT NULL DEFAULT CURRENT_TIMESTAMP

Note that I require that the name of the column be specifiable, so the timestamps macro is not suitable.

You can execute SQL in migration like this

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM