Skip to content
FR
  1. LuzineDebug
  2. Databases (SQL)
  3. ERROR 1054 (42S22): Unknown column 'email' in 'f…
Databases (SQL) Beginner ≈ 10 min to fix

Fix "ERROR 1054 (42S22): Unknown column in 'field list'" (MySQL)

Error message
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
In short

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.

Be the first to confirm this fix

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

  1. 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.
  2. Typo or wrong table: emial, user_email, or a column that belongs to another table, used without a JOIN.
  3. Alias or quotes: a SELECT alias reused in the WHERE (not allowed), a wrong alias prefix (u.email without a u alias), a value wrapped in backticks instead of single quotes (it becomes a column name) or double quotes with the ANSI_QUOTES mode.
  4. Columns added by the ORM: Eloquent writes created_at and updated_at by default, deleted_at with soft deletes; a form field passed as-is to create() also becomes a column.
  5. Wrong database: the application is connected to a different database from the one you inspect (.env, test database).

Step-by-step fix

  1. 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.

    sql
    SELECT DATABASE();
    SHOW COLUMNS FROM users;
    
    SELECT column_name
    FROM information_schema.columns
    WHERE table_schema = DATABASE() AND table_name = 'users';
  2. Check and run the migrations

    A Pending migration explains the error. In production, Laravel asks for confirmation: --force only skips it in a deploy script, so take a backup first. The equivalents for other frameworks follow.

    bash
    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
  3. Fix quotes and aliases

    In MySQL, backticks wrap names (tables, columns) and single quotes wrap values. A SELECT alias is not visible in the WHERE: repeat the expression or use HAVING.

    sql
    -- 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;
  4. Align the ORM model with the table

    If the table has no created_at/updated_at columns, disable the model timestamps, or add them with a migration using $table->timestamps();. Also restrict accepted fields with $fillable and only pass validated data to create().

    php
    <?php
    
    namespace App\Models;
    
    use Illuminate\Database\Eloquent\Model;
    
    class Visit extends Model
    {
        public $timestamps = false;
    
        protected $fillable = ['ip', 'path'];
    }
  5. Check the connection the application uses

    Make sure you inspect the same database as the application. With Laravel, php artisan db:show shows the active connection and php artisan db:table users the table columns. Remember to clear the config cache after changing .env.

    bash
    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

All Databases (SQL) errors →