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.
Currently available for 2-3 new projects
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 PortfolioRelated 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...