What does Ecto.Migration#references() :vaildate do?

In the docs for Ecto Migrations, it has the following description for the validate option you can pass to references.


:validate - Whether or not to validate the foreign key constraint on creation or not. Only available in PostgreSQL, and should be followed by a command to validate the foreign key in a following migration if false.

Does this mean it checks the foreign key constraint on record creation (so every time you make a new row, akin to validate_foreign_constraint() in Changeset?) or on field creation?

Edit: actually now I see that “validate” is set to true on the fk constraint, when I inspect with pgadmin, so I am assuming this act on-insertion and defaults to true, so it acts as you want by default.

I believe the use-case for this is to not validate the constraint so you can add new fields with such constraints, then populate the new fields with proper data, then enable validation (the “followed by a command to validate…”). This can make things possible (in the case of constraints that would fail until first population) or just faster (running validations costs time, and in a migration you may be able to guarantee the population is correct).

That’s how I’ve always read that, but I could be wrong :slight_smile: