PG::DuplicateColumn / Duplicate column name (migration) Ruby / Rails Origin: Application & API OSI layer 7 · Application Last updated 5 Nov 2026

Rails: ActiveRecord::StatementInvalid: PG::DuplicateColumn: ERROR: column "status" of relation "orders" already exists

A migration tried to add a column/table/index that already exists.

Exact message you may see PG::DuplicateColumn: ERROR: column "status" of relation "orders" already existsMysql2::Error: Duplicate column name 'status'PG::DuplicateTable: ERROR: relation "orders" already existsMysql2::Error: Table 'orders' already exists
Seen on: Ruby PostgreSQL

Meaning

Usually a migration was run partially, run manually, or merged from two branches. Check the schema (\d orders), schema_migrations entries, and make migrations idempotent (add_column ..., if_not_exists: true, column_exists?). Rolling back and re-running can fix half-applied migrations (PostgreSQL DDL is transactional, MySQL isn't).

Common causes

  • Migration applied partially or manually
  • Two branches adding the same column
  • Schema loaded then migrations rerun
  • MySQL non-transactional DDL left half-done
  • Duplicate migration files

⚡ Quick fix

  1. add_column :orders, :status, :string, if_not_exists: true
  2. Inspect schema_migrations and the table
  3. Remove the duplicate migration/file or fix the version

Detailed fix by platform

Rails

  1. bin/rails db:migrate:status | tail; bin/rails runner 'p Order.column_names'

How to diagnose

  1. Column — Exists?
  2. Version — In schema_migrations?
  3. Branches — Duplicate?

🔧 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: Application & API. Errors that are often confused with or caused by this one (click to open):

1022 — MySQL ERROR 1022 (23000): Can't write; duplicate key in table (MySQL)10221051 — MySQL ERROR 1051 (42S02): Unknown table 'x' (MySQL)10511060 — MySQL ERROR 1060 (42S21): Duplicate column name 'x' (MySQL)10601061 — MySQL ERROR 1061 (42000): Duplicate key name 'x' (MySQL)10611091 — 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)11462BP01 — ERROR: cannot drop table x because other objects depend on it (PostgreSQL)2BP0142701 — ERROR: column "x" of relation "y" already exists (PostgreSQL)42701PG::Dupli…

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.