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.
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 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
add_column :orders, :status, :string, if_not_exists: true- Inspect
schema_migrationsand the table - Remove the duplicate migration/file or fix the version
Detailed fix by platform
Rails
bin/rails db:migrate:status | tail; bin/rails runner 'p Order.column_names'
How to diagnose
- Column — Exists?
- Version — In schema_migrations?
- 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:
Similar errors
Most viewed in Ruby / Rails
- ActionController::InvalidAuthenticityToken Rails: ActionController::InvalidAuthenticityToken (Can't verify CSRF token authenticity)
- undefined method for nil Ruby: NoMethodError: undefined method `x' for nil (nil:NilClass)
- CORS blocked in Rails API (rack-cors) Browser: Access to fetch at 'http://localhost:3000/api/items' from origin 'http://localhost:5173' has been blocked by CORS policy — Rails
Other ways to find it
Where this error sits
Origin: Application & API. Errors that are often confused with or caused by this one (click to open):
🧠 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.
Report a correction or suggest an improvement
Last updated 5 Nov 2026