Reputation: 4420
How do I write a migration in Ecto to remove a column's default value? Let's say I have a table called :users
with a column called :timezone
that previously had defaulted to "Etc/UTC"...
Here's the start of my migration...
def up do
alter table(:users) do
modify :timezone, :string, default: fragment("NULL"), null: true
end
end
def down do
alter table(:users) do
modify :timezone, :string, default: "Etc/UTC", null: false
end
end
Upvotes: 3
Views: 3275
Reputation:
From https://www.postgresql.org/docs/9.3/static/ddl-default.html
If no default value is declared explicitly, the default value is the null value.
So @Dogbert is correct, default: nil
is the way to go.
If you really want to, you could directly write the SQL command ALTER COLUMN "timezone" DROP DEFAULT
using execute/1
.
Upvotes: 1