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

  1. Create the unique index on those columns
  2. Match the columns exactly
  3. Use ON CONFLICT ON CONSTRAINT name

Detailed fix by platform

PostgreSQL

  1. CREATE UNIQUE INDEX IF NOT EXISTS users_email_key ON users (email);

How to diagnose

  1. Index — Unique index on those exact columns?
  2. 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.