could not create exclusion constraint “…”
Symptoms
A statement failed with SQLSTATE 23P01 (exclusion_violation), reported at severity ERROR. This is a Integrity Constraint Violation condition: PostgreSQL emits the message could not create exclusion constraint "…".
- The client receives SQLSTATE
23P01(exclusion violation). - The operation is rejected at
ERRORlevel; the statement does not complete. - The server adds a
DETAILline with specifics (see below).
What the server log shows
ERROR: could not create exclusion constraint "…"
DETAIL: Key … conflicts with key ….
Why PostgreSQL raises this
Class 23 (Integrity Constraint Violation) is raised when a write would break a declared constraint — NOT NULL, CHECK, UNIQUE/primary key, foreign key, or exclusion.
As described in PostgreSQL’s Section 5.4 Constraints and Appendix A (PostgreSQL Error Codes), SQLSTATE 23P01 carries the condition name exclusion_violation in class Integrity Constraint Violation. (Paraphrased — see the linked reference for the exact wording.)
Common causes
- A duplicate value violated a unique or primary-key constraint.
- A referencing row had no matching parent (foreign key).
- A NOT NULL column received NULL, or a CHECK predicate failed.
- An exclusion constraint rejected overlapping values.
How to fix it
- Identify the offending row and reconcile it with the constraint.
- Insert or fix the referenced parent row before the child.
- Use
ON CONFLICTto handle duplicates intentionally. - Review the constraint definition to confirm it matches the data model.
Version applicability
This message is present in PostgreSQL 15, 16, 17, 18 and 19.
Related & next steps
Reference: PostgreSQL Section 5.4 Constraints.