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.

Currently available for 2-3 new projects

Hafiz Riaz

About Hafiz

Full Stack Developer from Italy. I build web applications with Laravel and Vue.js, and automate business processes. Creator of ReplyGenius, StudyLab, and other SaaS products.

View Portfolio

Related Errors