SQLSTATE 23001Severity mediumLab verified

Incident brief

RESTRICT foreign-key violation

Deleting or updating a parent row referenced by a child fails when the foreign key uses RESTRICT (or NO ACTION with a still-present child); the referencing rows must go first.

Reproduced on PostgreSQL 18.4Verified 2026-07-24 (isolated lab, PostgreSQL 18.4)Reviewed by Verified against PostgreSQL 18.4 in an isolated lab environment

In 10 seconds

What
RESTRICT foreign-key violation
What triggers it
Create a parent/child foreign key with RESTRICT and insert a referenced parent row plus a child that references it.
The fix
Delete or reassign the referencing child rows before deleting the parent.
Proof
Reproduced on PostgreSQL 18.4 → A DELETE on the parent reproduces SQLSTATE 23001; RESTRICT blocks it and the DETAIL names the referencing child key.

The fix

What to do right now

The immediate, application-level response to this error.

  • Delete or reassign the referencing child rows before deleting the parent.
  • Or, if cascade semantics are intended, define the foreign key ON DELETE CASCADE deliberately.
Fix — SQL
-- Remove the referencing child rows first.
DELETE FROM child_r WHERE pid = 1;
DELETE FROM parent_r WHERE id = 1;

Related & next steps

Follow the thread

Everything this error touches — jump straight to the sibling error, term, runbook, or parameter.

Verification

PG 18.4
Last verified
2026-07-24 (isolated lab, PostgreSQL 18.4)
Reviewed by
Verified against PostgreSQL 18.4 in an isolated lab environment
Audit status
reviewed