Ecto migration -- how do I declare a column to have a default value of null?

What is the correct syntax for declaring that a column in an Ecto migration should have a default value of null?

The docs seem to suggest that null (or nil) are not options for setting a default: Ecto.Migration — Ecto SQL v3.7.1

The default default is null. If you add a (nullable) column and don’t specify a default, that column will use null as its default value.

5 Likes

It’s says in the docs (under “Options”):

:null - when false, the column does not allow null values.

So you can set it to true if you like, but as @zzq mentioned, it’s the default so it’s unnecessary.

1 Like