且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何使用Ecto的时间戳将时间戳添加到现有表中?

更新时间:2022-05-28 07:39:03

时间戳/ 1 函数接受选项关键字列表,您可以使用它设置默认值。

The timestamps/1 function accepts an options keyword list, you can set the default value with it.

def change do
  alter table(:channels) do
    timestamps default: "2016-01-01 00:00:01", null: false
  end
end


UPDATE Ecto> = 2.1

您需要使用新的类型 NaiveDateTime

def change do
  alter table(:channels) do
    timestamps default: ~N[2017-01-01 00:00:01], null: false
  end
end

如果您还有更多疑问,请查看文档

If you have more doubts take a look at the documentation