DBAtlas · Database operations atlas

42P07: duplicate_table

PostgreSQL

What does it mean?

The table (or similar object) being created already exists. CREATE failed because an object with the same name is present.

Why does it happen?

Re-creating an existing table with CREATE TABLE; running the script twice; re-applying migrations; a name clash with a view/sequence/index of the same name.

How to fix it

Use IF NOT EXISTS to skip creation when the object already exists: CREATE TABLE IF NOT EXISTS my_table (...). If you really want to re-create it, drop it first: DROP TABLE IF EXISTS my_table; Make migrations safe to re-run (idempotent). Check the existing object with \dt.

Open in DBAtlas →

More from this engine