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

**Code:** `Mysql2::Error: Unknown column in field list` · **Category:** Ruby / Rails · **Seen on:** Ruby, MySQL

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

## 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?

---
Source: [WhatIsMyError](https://whatismyerror.com/errors/ruby/activerecord-statementinvalid-mysql-unknown-column)
