Skip to content

Commit ecd87ed

Browse files
Map postgres :restrict_violation to :foreign_key constraint (#713)
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.
1 parent 57d7c4f commit ecd87ed

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

lib/ecto/adapters/postgres/connection.ex

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@ if Code.ensure_loaded?(Postgrex) do
2828
),
2929
do: [foreign_key: constraint]
3030

31+
def to_constraints(
32+
%Postgrex.Error{postgres: %{code: :restrict_violation, constraint: constraint}},
33+
_opts
34+
),
35+
do: [foreign_key: constraint]
36+
3137
def to_constraints(
3238
%Postgrex.Error{postgres: %{code: :exclusion_violation, constraint: constraint}},
3339
_opts

0 commit comments

Comments
 (0)