SQLSTATE[42S22]: Column not found: 1054 Unknown column
The query names a column the table does not have. Run the pending migration, fix the name or table prefix, and never sort by a raw request value.
- Message
- SQLSTATE[42S22]: Column not found: 1054 Unknown column 'titel' in 'where clause'
- Exception
- Illuminate\Database\QueryException
What it means
MySQL could not find a column the query names, so it rejected the whole statement. The last part of the message says where in the query the name appeared: 'field list' for a select, 'where clause' for a where, 'order clause' for an orderBy, and 'group statement' for a groupBy. Laravel throws Illuminate\Database\QueryException and appends the full SQL, which shows the exact name it sent.
Why it happens
- A migration has not run on this environment. The code expects a new column, the database does not have it yet.
php artisan migrate:statuslists the migration asPending. - A typo.
where('titel', ...)fails withUnknown column 'titel' in 'where clause'. - The wrong table in a join. After joining
users,where('posts.email', ...)fails becauseemaillives onusers. Leaving the prefix off a column both tables have gives a different error:1052 Column 'created_at' in where clause is ambiguous. - A request value used as a column name.
orderBy($request->query('sort'))with?sort=newestfails in the'order clause'. The query builder docs warn that PDO cannot bind column names, so user input should never choose them. - An accessor used as a column. An
excerptaccessor exists only on the PHP model.where('excerpt', ...)is sent to MySQL and fails.
How to fix it
Check for pending migrations and run them. In production, migrate asks for confirmation unless you pass --force:
php artisan migrate:status
php artisan migrate --pretend
php artisan migrate --force
--pretend prints the SQL without running it, so you can see the column it would add. Make running migrations part of every deploy, so code never reaches a database that is behind it.
For a typo, compare the name in the SQL with the table. php artisan db:table posts lists its columns.
In joins, prefix every column with its table:
$posts = Post::query()
->join('users', 'users.id', '=', 'posts.user_id')
->where('users.email', $email)
->select('posts.*')
->get();
For sorting from the request, map the allowed values to columns and fall back to a default:
$column = match ($request->query('sort')) {
'title' => 'title',
'oldest' => 'created_at',
default => 'id',
};
$posts = Post::orderBy($column)->get();
For an accessor, filter on the real columns it is built from, or load the rows and filter the collection in PHP.
Find it in production
With APP_DEBUG=false the visitor gets a 500 page titled "Server Error". Laravel reports the exception and writes it at error level to storage/logs/laravel.log, with the SQL in the message. A missing migration fails every request that touches the column right after a deploy; a sort parameter fails only for the visitors who send that value. Ranetrace's error monitoring records each reported exception with its stack trace and the request it happened on.
Reproduced on Laravel 13.45, PHP 8.5, MySQL 8.0.27, 5 December 2026.
Related
Read more
Start monitoring today
Websites go down and code throws errors. Ranetrace tells you when it happens to yours, why it matters and what to do next.