Error Reference › SQL / Database
SQL / Database
Unknown column (1054)
The query names a column that doesn't exist in that table.
What it looks like
ERROR 1054 (42S22): Unknown column 'emial' in 'field list'
What does "Unknown column (1054)" mean?
Returned by MySQL when a query names a column that is not in the table. The second quoted part says where in the query it appeared — field list (the SELECT columns), where clause, on clause or order clause.
What causes "Unknown column (1054)"?
- Typo or wrong case in the column name.
- Column belongs to a different table/alias.
- Migration that adds the column hasn't run.
How do I confirm the cause?
- Run DESCRIBE tablename and compare the real column names with the one in the message.
- If the query joins tables, check the column is prefixed with the right table alias.
- If the column should exist, check whether the migration that adds it has been run in this environment.
- If the message says where clause and the name is a column alias from the SELECT list, that is the cause: MySQL does not let WHERE refer to an alias — repeat the expression or use HAVING.
How do I fix "Unknown column (1054)"?
- Check the column name and which table it's on.
- Qualify ambiguous columns with the table/alias.
- Run pending migrations.
How do I stop it happening again?
- Run migrations as part of every deploy, before the new code goes live.
- Use a query builder or ORM that fails on unknown columns during tests.