42P07 PostgreSQL Origin: Data OSI layer 7 · Application Last updated 14 Oct 2026

ERROR: relation "x" already exists

CREATE TABLE/INDEX/SEQUENCE used a name that already exists in that schema.

Seen on: PostgreSQL

Meaning

Migrations run twice, migration history out of sync with the real schema, or index names colliding (index names are unique per schema, not per table).

Common causes

  • Migration re-run or history table out of sync
  • Same index name used on two tables
  • Restoring into a non-empty database

⚡ Quick fix

  1. Use IF NOT EXISTS
  2. Give indexes table-specific names
  3. Sync migration state (e.g. mark as applied) carefully

Detailed fix by platform

PostgreSQL

  1. CREATE INDEX IF NOT EXISTS orders_user_id_idx ON orders (user_id);

How to diagnose

  1. Object — Table, index or sequence?
  2. Migrations — History matches schema?

🔧 Still not fixed?

Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:

Where this error sits

Origin: Data. Errors that are often confused with or caused by this one (click to open):

1051 — MySQL ERROR 1051 (42S02): Unknown table 'x' (MySQL)10511060 — MySQL ERROR 1060 (42S21): Duplicate column name 'x' (MySQL)10601091 — MySQL ERROR 1091 (42000): Can't DROP 'x'; check that column/key exists (MySQL)10911146 — MySQL ERROR 1146 (42S02): Table 'db.table' doesn't exist (MySQL)11462714 — SQL Server Msg 2714: There is already an object named 'X' in the database (SQL)27142BP01 — ERROR: cannot drop table x because other objects depend on it (PostgreSQL)2BP0142701 — ERROR: column "x" of relation "y" already exists (PostgreSQL)4270142P01 — PostgreSQL: ERROR: relation "x" does not exist (PostgreSQL)42P0142P07

Explore the map of this error Full error map →

🧠 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.