`Ecto.Changeset.validate_change` and setting fields to `nil`

As the docs say (emphasis mine):

It invokes the validator function to perform the validation only if a change for the given field exists and the change value is not nil.

https://hexdocs.pm/ecto/Ecto.Changeset.html#validate_change/3

That’s because most validations do not want to run on nil. You have one of the few exceptions. :slight_smile:

2 Likes