Skip to content

Conversation

@ashutoshrishi
Copy link
Contributor

@ashutoshrishi ashutoshrishi commented Jan 8, 2026

In PostgreSQL 18, this error code is now used for ON DELETE RESTRICT constraint violation. The existing :foreign_key_violation error code is raised for ON DELETE NO ACTION.

The behaviour changed in postgres commit
postgres/postgres@086c84b

The change is backwards compatible as the error code was not previously raised even though it existed in the postgres documentation. It is now correctly raised for the ON DELETE RESTRICT constraint.

Resolves #712

The example provided in the ISSUE now correctly returns a changeset instead of raising:

{:error,
 #Ecto.Changeset<
   action: :delete,
   changes: %{},
   errors: [
     children: {"does not exist",
      [constraint: :foreign, constraint_name: "child_parent_id_fkey"]}
   ],
   data: #Foo.Parent<>,
   valid?: false,
   ...
 >}

In PostgreSQL 18, this error code is now used for `ON DELETE RESTRICT`
constraint violation. The existing `:foreign_key_violation` error code
is raised for `ON DELETE NO ACTION`.

The behaviour changed in postgres commit
postgres/postgres@086c84b

The change is backwards compatible as the error code was not previously
raised even though it existed in the postgres documentation. It is now
correctly raised for the `ON DELETE RESTRICT` constraint.
@josevalim josevalim merged commit ecd87ed into elixir-ecto:master Jan 9, 2026
11 checks passed
@josevalim
Copy link
Member

💚 💙 💜 💛 ❤️

@ashutoshrishi ashutoshrishi deleted the fix/postgres-restrict-violation-constraint branch January 9, 2026 22:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

PostgreSQL restrict_violation not mapped to a foreign_key constraint in PostgreSQL 18

3 participants