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).
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 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
bin/rails db:migrateand restart- Compare
db/schema.rbwithDESCRIBE users - Deploy migrations before code that needs them
Detailed fix by platform
Rails
bin/rails runner 'p User.column_names'
How to diagnose
- Column — In table?
- Migration — Run?
- 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:
Similar errors
- ActiveRecord::AssociationTypeMismatch Rails: ActiveRecord::AssociationTypeMismatch: User(#1234) expected, got "42" which is an instance of String(#5678)
- ActiveRecord::ConnectionNotEstablished Rails: ActiveRecord::ConnectionNotEstablished: No connection pool for 'ActiveRecord::Base' found
- ActiveRecord::Deadlocked: PG::TRDeadlockDetected Rails: ActiveRecord::Deadlocked: PG::TRDeadlockDetected: ERROR: deadlock detected
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