Mysql2::Error: Unknown column in field list Ruby / Rails Origin: Application & API OSI layer 7 · Application Last updated 5 Nov 2026

Rails: ActiveRecord::StatementInvalid: Mysql2::Error: Unknown column 'users.nickname' in 'field list'

The query references a column that doesn't exist in the table (missing migration, typo or stale schema cache).

Exact message you may see ActiveRecord::StatementInvalid: Mysql2::Error: Unknown column 'users.nickname' in 'field list'Mysql2::Error: Unknown column 'x' in 'where clause'PG::UndefinedColumn: ERROR: column users.nickname does not existActiveModel::MissingAttributeError: missing attribute: nicknameActiveRecord::StatementInvalid Unknown column
Seen on: Ruby MySQL

Meaning

Run migrations (bin/rails db:migrate), restart the app (schema cache), check db/schema.rb vs the DB, and column names in where/select/order. In production with preloaded schema caches, deploy migrations before code.

Common causes

  • Migration not run on this DB
  • Typo/renamed column
  • Stale schema cache
  • Deploy order (code before migration)
  • Wrong database

⚡ Quick fix

  1. bin/rails db:migrate and restart
  2. Compare db/schema.rb with DESCRIBE users
  3. Deploy migrations before code that needs them

Detailed fix by platform

Rails

  1. bin/rails runner 'p User.column_names'

How to diagnose

  1. Column — In table?
  2. Migration — Run?
  3. Deploy — Order?

🔧 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):

ActiveRecord::AssociationTypeMismatch — Rails: ActiveRecord::AssociationTypeMismatch: User(#1234) expected, got "42" which is an instance of String(#5678) (Ruby / Rails)ActiveRecord::Associa…ActiveRecord::ConnectionNotEstablished — Rails: ActiveRecord::ConnectionNotEstablished: No connection pool for 'ActiveRecord::Base' found (Ruby / Rails)ActiveRecord::Connect…ActiveRecord::Deadlocked: PG::TRDeadlockDetected — Rails: ActiveRecord::Deadlocked: PG::TRDeadlockDetected: ERROR: deadlock detected (Ruby / Rails)ActiveRecord::Deadloc…ActiveRecord::PendingMigrationError — Rails: ActiveRecord::PendingMigrationError — Migrations are pending. To resolve this issue, run: bin/rails db:migrate (Ruby / Rails)ActiveRecord::Pending…PG::ConnectionBad: could not connect to server — Rails: PG::ConnectionBad: could not connect to server: Connection refused. Is the server running on host "localhost" (127.0.0.1) and accepting TCP/IP connections on port 5432? (Ruby / Rails)PG::ConnectionBad: co…PG::UndefinedTable: relation does not exist — Rails: ActiveRecord::StatementInvalid: PG::UndefinedTable: ERROR: relation "users" does not exist (Ruby / Rails)PG::UndefinedTable: r…SQLSTATE[42S22]: Column not found — Laravel: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'status' in 'field list' (Laravel)SQLSTATE[42S22]: Colu…Mysql2::E…

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.