How to add timestamps to an existing table with Ecto's timestamps?
问题 Since inserted_at and updated_at can not be null this won't work: def change do alter table(:channels) do timestamps end end ** (Postgrex.Error) ERROR (not_null_violation): column "inserted_at" contains null values Is there an easy way to accomplish this without copying timestamps ' functionality? 回答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