Fix "ERROR 1054 (42S22): Unknown column in 'field list'" (MySQL)
ERROR 1054 (42S22): Unknown column 'email' in 'field list'
- SQLSTATE[42S22]: Column not found: 1054 Unknown column 'email' in 'field list'
- ERROR 1054 (42S22): Unknown column 'u.email' in 'where clause'
- ERROR 1054 (42S22): Unknown column 'john' in 'where clause'
- ERROR: column "email" of relation "users" does not exist
- sqlite3.OperationalError: no such column: email
The query uses a column that does not exist in the target table: migration not run on this database, a typo, a wrong alias, or a value wrapped in backticks instead of single quotes. Check the real structure with SHOW COLUMNS FROM users;, run the missing migrations, then fix the name or the quotes in the query.
What this error means
MySQL found the table, but an identifier in the query does not match any column of the tables listed in FROM and JOIN. The part after in tells where it is: 'field list' for the SELECT list or the columns of an INSERT/UPDATE, 'where clause', 'order clause', 'on clause', 'group statement'. The check happens when the query is parsed, before any row is read. With an ORM, the query is generated from the model: the error then reveals a mismatch between the code and the real database schema.
Common causes
- Migration not run on this environment: the column exists locally but not in production or in the test database, or the migration was rolled back.
- Typo or wrong table:
emial,user_email, or a column that belongs to another table, used without aJOIN. - Alias or quotes: a
SELECTalias reused in theWHERE(not allowed), a wrong alias prefix (u.emailwithout aualias), a value wrapped in backticks instead of single quotes (it becomes a column name) or double quotes with theANSI_QUOTESmode. - Columns added by the ORM: Eloquent writes
created_atandupdated_atby default,deleted_atwith soft deletes; a form field passed as-is tocreate()also becomes a column. - Wrong database: the application is connected to a different database from the one you inspect (
.env, test database).
Step-by-step fix
-
Compare the query with the real structure
Spot the column name and the clause in the message, then list the table columns on the database the application uses.
SELECT DATABASE(); SHOW COLUMNS FROM users; SELECT column_name FROM information_schema.columns WHERE table_schema = DATABASE() AND table_name = 'users'; -
Check and run the migrations
A
Pendingmigration explains the error. In production, Laravel asks for confirmation:--forceonly skips it in a deploy script, so take a backup first. The equivalents for other frameworks follow.php artisan migrate:status php artisan migrate php bin/console doctrine:migrations:migrate python manage.py migrate bin/rails db:migrate npx prisma migrate deploy -
Fix quotes and aliases
In MySQL, backticks wrap names (tables, columns) and single quotes wrap values. A
SELECTalias is not visible in theWHERE: repeat the expression or useHAVING.-- Wrong: backticks turn 'john' into a column name SELECT * FROM users WHERE name = `john`; -- Right: a string literal SELECT * FROM users WHERE name = 'john'; -- Wrong: SELECT alias used in WHERE SELECT price * qty AS total FROM orders WHERE total > 100; -- Right: repeat the expression SELECT price * qty AS total FROM orders WHERE price * qty > 100; -
Align the ORM model with the table
If the table has no
created_at/updated_atcolumns, disable the model timestamps, or add them with a migration using$table->timestamps();. Also restrict accepted fields with$fillableand only pass validated data tocreate().<?php namespace App\Models; use Illuminate\Database\Eloquent\Model; class Visit extends Model { public $timestamps = false; protected $fillable = ['ip', 'path']; } -
Check the connection the application uses
Make sure you inspect the same database as the application. With Laravel,
php artisan db:showshows the active connection andphp artisan db:table usersthe table columns. Remember to clear the config cache after changing.env.php artisan config:clear php artisan db:show php artisan db:table users
Did this fix work for you?
Confirm it in one click: it will rise for the next developers stuck on the same error.
Keep it from coming back
- Run migrations in the deploy pipeline, before switching traffic to the new code version.
- Never change the schema by hand: every column change goes through a versioned migration.
- Run tests on the same engine as production (MySQL rather than SQLite) to catch schema gaps.
Frequently asked questions
What does "in 'field list'" mean?
The unknown column is in the column list: those of the SELECT, or those of an INSERT or UPDATE. For 'where clause' or 'order clause', look in the WHERE or ORDER BY.
Why does it work locally but not in production?
The migration that adds the column was not run in production. Check with php artisan migrate:status (or your framework’s equivalent) on the server.
Why "Unknown column 'updated_at'" with Laravel?
Eloquent fills created_at and updated_at on every write. Add those columns with $table->timestamps(); or set public $timestamps = false; in the model.
Useful tools for this error
More Databases (SQL) errors
- Fix "ERROR 1045 (28000): Access denied for user 'root'@'localhost'" (MySQL, MariaDB)
- Fix "ERROR 1062 (23000): Duplicate entry for key" (MySQL, MariaDB, PostgreSQL)
- Fix "Deadlock found when trying to get lock; try restarting transaction" (MySQL, PostgreSQL)
- Fix FATAL: password authentication failed for user "postgres" (PostgreSQL)
- Fix "ERROR 1040: Too many connections" (MySQL) and "too many clients already" (PostgreSQL)
- Fix "ERROR 2006 (HY000): MySQL server has gone away"
- Fix "ERROR: relation "users" does not exist" (PostgreSQL)