ERROR: there is no unique or exclusion constraint matching the ON CONFLICT specification
INSERT … ON CONFLICT (cols) names columns that don’t have a matching unique index/constraint.
there is no unique or exclusion constraint matching the ON CONFLICT specification Meaning
ON CONFLICT needs an existing unique constraint on exactly those columns (or a matching partial index predicate).
Common causes
- No unique index on the conflict columns
- Column order/set differs from the index
- Partial unique index without WHERE in ON CONFLICT
⚡ Quick fix
- Create the unique index on those columns
- Match the columns exactly
- Use ON CONFLICT ON CONSTRAINT name
Detailed fix by platform
PostgreSQL
CREATE UNIQUE INDEX IF NOT EXISTS users_email_key ON users (email);
How to diagnose
- Index — Unique index on those exact columns?
- Recent change — Did it start after a deploy, upgrade, or configuration change? Compare with the last working version.
🔧 Still not fixed?
Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:
Similar errors
- 08P01 ERROR: bind message supplies 2 parameters, but prepared statement requires 1
- 1093 MySQL ERROR 1093 (HY000): You can't specify target table 'x' for update in FROM clause
- 1175 MySQL ERROR 1175 (HY000): You are using safe update mode and you tried to update a table without a WHERE that uses a KEY column
Most viewed in PostgreSQL
- prepared statement exists ERROR: prepared statement "s1" already exists (PgBouncer transaction mode)
- incompatible data directory FATAL: database files are incompatible with server — The data directory was initialized by PostgreSQL version 15, which is not compatible with this version 16
- postmaster.pid FATAL: lock file "postmaster.pid" already exists — Is another postmaster running in data directory?
Other ways to find it
Where this error sits
Origin: Data. Errors that are often confused with or caused by this one (click to open):
🧠 Still stuck? Analyze your error
Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.
💬 What worked for others
No tips yet — did something else fix this for you?
Share what worked for you
Tips are checked by an editor before they appear. Links are removed.
Report a correction or suggest an improvement
Last updated 15 Oct 2026