Ecto Schema (ArgumentError) invalid option :null for field/3

I am trying to add the option “null” to the macro field but it says I can not:

ArgumentError) invalid option :null for field/3

Stacktrace:
│ (ecto 3.8.4) lib/ecto/schema.ex:2208: Ecto.Schema.check_options!/3
│ (ecto 3.8.4) lib/ecto/schema.ex:1917: Ecto.Schema.field/4
│ lib/spent_control/spends/spend_type.ex:6: (module)
│ (stdlib 3.14) erl_eval.erl:680: :erl_eval.do_apply/6

please advise.

1 Like

null is not an option for schema fields, it’s an option for database columns. You need to put it in the migration.

Prior to Ecto 3.8.0 (released in April 2022), unknown options passed to field would be silently ignored (instead of raising an error) so you may find tutorials / StackOverflow answers / etc that still pass them.

3 Likes