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
SQLSTATE[42S02]: Base table or view not found
Common Causes
- 1 Migrations not run
- 2 Table name misspelled in model or query
- 3 Wrong database connection
- 4 Model using wrong table name
- 5 Database not properly configured
Solutions
Run pending migrations
php artisan migrate
Check if table exists and migrate fresh
php artisan migrate:fresh
Specify correct table name in model
class Post extends Model
{
protected $table = 'posts';
}
Verify database connection
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.
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
Migration Failed in Laravel - How to Debug and Fix
Migration table not found / Migration fa...
Laravel Database Connection Refused Error - Fix
SQLSTATE[HY000] [2002] Connection refuse...
Laravel Access Denied for Database User - Fix
SQLSTATE[HY000] [1045] Access denied for...