PostgreSQL errors
PostgreSQL: column already exists
ERRORSQLSTATE 42701duplicate_column
ERROR: column "<name>" of relation "<t>" already existsYou tried to add a column that already exists on the table. Use ADD COLUMN IF NOT EXISTS, or guard the migration so it does not run twice.
What this error means
ALTER TABLE ... ADD COLUMN fails if a column by that name already exists. It almost always means a migration was applied more than once.
How to fix it
01
The column already exists
Use IF NOT EXISTS so the add is safe to repeat.
sql
ALTER TABLE users ADD COLUMN IF NOT EXISTS last_login timestamptz;02
The migration ran twice
Ensure your migration runner records applied migrations, or guard each change.
How to avoid it next time
- Make migrations idempotent.
- Use IF NOT EXISTS on additive schema changes.
Frequently asked questions
How do I add a column only if it is missing?
ALTER TABLE t ADD COLUMN IF NOT EXISTS col type; It is a no-op if the column already exists.
Why did this happen in my migration?
The same migration applied twice. Track migration state, or use IF NOT EXISTS so re-running is harmless.
Stop struggling with SQL
Use FluentDB, the AI database client for macOS.
Related errors
Part of the PostgreSQL error reference. Last reviewed 2026-07-31.