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.
Seen on:
PostgreSQL
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 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.
Was this page helpful?
Report a correction or suggest an improvement
Last updated 2 Oct 2026