Database Laravel 8 Laravel 9 Laravel 10 Laravel 11 Laravel 12

SQLSTATE 42S02 Table Not Found in Laravel - Fix

This database error occurs when Laravel tries to query a table that doesn't exist in the database.

The Error

Error Message
SQLSTATE[42S02]: Base table or view not found

Common Causes

  1. 1 Migrations not run
  2. 2 Table name misspelled in model or query
  3. 3 Wrong database connection
  4. 4 Model using wrong table name
  5. 5 Database not properly configured

Solutions

1

Run pending migrations

Bash
php artisan migrate
2

Check if table exists and migrate fresh

Bash
php artisan migrate:fresh
3

Specify correct table name in model

PHP
class Post extends Model
{
    protected $table = 'posts';
}
4

Verify database connection

Bash
php artisan tinker
>>> DB::connection()->getDatabaseName()

Need Help With Your Laravel Project?

I specialize in building custom Laravel applications, process automation, and SaaS development. Whether you need to eliminate repetitive tasks or build something from scratch, let's discuss your project.

Hafiz Riaz

About Hafiz

Senior Full Stack Developer. I build production software with Laravel, Filament, Vue, and AI integrations, and write about the real decisions behind shipping it.

Get in touch →

Related Errors