# SQLSTATE[42S02]: Base table or view not found: 1146 Table doesn't exist

MySQL has no table by the name the query used, in the database it named. Run the migrations, check the connection, or set the table name on the model.

Message:

```text
SQLSTATE[42S02]: Base table or view not found: 1146 Table 'shop.post_categories' doesn't exist
```

Exception:

```text
Illuminate\Database\QueryException
```

## What it means

The query names a table that does not exist in the database it ran against. MySQL writes the name as `database.table`, so `'shop.post_categories'` tells you both where Laravel looked and what it looked for. Laravel throws `Illuminate\Database\QueryException` and appends the SQL.

## Why it happens

- The migrations have not run on this environment, or not all of them. A fresh server or a new database has no tables until `php artisan migrate` creates them.
- The app is connected to another database than you think. Compare the database name in the message with the one you expect. A different `DB_DATABASE`, a stale config cache, or a model with its own connection all send the query elsewhere.
- Eloquent guesses the table name from the class. The docs: the snake case, plural name of the class. A `PostCategory` model reads `post_categories`. If the migration created `post_category`, every query on the model fails.
- A framework table is missing. With `SESSION_DRIVER=database`, `CACHE_STORE=database` or `QUEUE_CONNECTION=database`, Laravel needs the `sessions`, `cache` and `jobs` tables. The default migrations create them; an app that dropped those migrations, or a database that skipped them, fails on `'sessions'`, `'cache'` or `'jobs'`.

## How to fix it

See which migrations ran and run the rest:

```bash
php artisan migrate:status
php artisan migrate --force
```

`--force` skips the confirmation prompt Laravel shows in production. `migrate:status` reads the `migrations` table, so a table dropped by hand still shows as `Ran`. In that case check the database itself:

```bash
php artisan db:show
```

It prints the connection, host, port and database name, and lists the tables. If the database is the wrong one, correct `DB_DATABASE` and rebuild the config cache:

```bash
php artisan config:cache
```

If the model's table name is not the guessed one, name it with the `Table` attribute:

```php
use Illuminate\Database\Eloquent\Attributes\Table;
use Illuminate\Database\Eloquent\Model;

#[Table('post_category')]
class PostCategory extends Model
{
}
```

A `protected $table = 'post_category';` property does the same.

For a missing framework table, look in `database/migrations` first. The default migrations create `sessions`, `cache` and `jobs`, so if they are still there, run `php artisan migrate`. While they are, the commands below stop with "Migration already exists." Only if they were deleted, recreate them and migrate:

```bash
php artisan make:session-table
php artisan make:cache-table
php artisan make:queue-table
php artisan migrate
```

## Find it in production

With `APP_DEBUG=false` the visitor gets a 500 page titled "Server Error". A missing model table breaks only the pages that use that model. A missing `sessions` table breaks every page in the `web` middleware group, because the session is read before your code runs. A missing `jobs` table breaks the request that dispatches the job.

Laravel reports the exception and writes it at error level to `storage/logs/laravel.log`, with the table name in the message, so Ranetrace's [error monitoring](/features/error-monitoring) records it with the page it broke. The exception is a missing `jobs` or `cache` table when Ranetrace's own queue or cache store is the database: its report travels through them, so that one is lost and the log file is where to look. When the table behind every page is gone, such as `sessions`, the whole site is down: Ranetrace's [uptime check](/features/uptime-monitoring) requests your site about every minute and alerts you once it has been down for two minutes.

Reproduced on Laravel 13.45, PHP 8.5, MySQL 8.0.27, 5 December 2026.

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

## Related

### Terms

- [Eloquent ORM in Laravel](https://ranetrace.com/glossary/eloquent-orm-in-laravel.md)
- [Configuration caching in Laravel](https://ranetrace.com/glossary/configuration-caching-in-laravel.md)

### Other errors

- [SQLSTATE\[42S22\]: Column not found: 1054 Unknown column](https://ranetrace.com/error-guides/laravel-sqlstate-1054-unknown-column.md)
- [SQLSTATE\[HY000\] \[2002\] Connection refused](https://ranetrace.com/error-guides/laravel-sqlstate-2002-connection-refused.md)

Read this guide in a browser: https://ranetrace.com/error-guides/laravel-sqlstate-1146-table-not-found
