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

```text
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'titel' in 'where clause'
```

Exception:

```text
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:status` lists the migration as `Pending`.
- A typo. `where('titel', ...)` fails with `Unknown column 'titel' in 'where clause'`.
- The wrong table in a join. After joining `users`, `where('posts.email', ...)` fails because `email` lives on `users`. 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=newest` fails 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 `excerpt` accessor 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`:

```bash
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:

```php
$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:

```php
$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](/features/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.

Read more: https://laravel.com/docs/queries

## Related

### Terms

- [Query builder in Laravel](https://ranetrace.com/glossary/query-builder-in-laravel.md)
- [Eloquent ORM in Laravel](https://ranetrace.com/glossary/eloquent-orm-in-laravel.md)

### Other errors

- [SQLSTATE\[42S02\]: Base table or view not found: 1146 Table doesn't exist](https://ranetrace.com/error-guides/laravel-sqlstate-1146-table-not-found.md)
- [SQLSTATE\[23000\]: Integrity constraint violation: 1062 Duplicate entry](https://ranetrace.com/error-guides/laravel-sqlstate-1062-duplicate-entry.md)

Read this guide in a browser: https://ranetrace.com/error-guides/laravel-sqlstate-1054-unknown-column
