Knowledge
SQLSTATE[42S02] Base table or view not found
#Databases
This MySQL error means your query references a table that does not exist in the connected database. In Laravel it almost always means migrations have not run, or you are connected to the wrong database.
Published by Mark van Eijk on June 23, 2026 · 1 minute read
- About the error
- Why do I see this error
- Solution
- Run your migrations
- Confirm you're on the right database
- Check the model's table name
About the error
In Laravel the message reads:
SQLSTATE[42S02]: Base table or view not found: 1146 Table 'my_app.users' does not exist
The query is valid SQL, but the table it names isn't present in the database you're connected to.
Why do I see this error
- Your migrations haven't run, so the table was never created.
- You're connected to the wrong database (wrong
DB_DATABASE, or a fresh/empty database). - The table name has a typo, or you renamed it without updating the model's
$table. - A migration failed halfway and the table was rolled back or never committed.
Solution
Run your migrations
The most common fix, especially on a fresh checkout or a new environment:
php artisan migrate
To check what has and hasn't run:
php artisan migrate:status
On a development database you can rebuild everything from scratch:
php artisan migrate:fresh
Be careful: migrate:fresh drops every table first. Never run it against a database with data you care about.
Confirm you're on the right database
Verify your connection settings point where you think they do:
DB_DATABASE=my_app
Then check the table really exists there:
SHOW TABLES FROM my_app;
If the value changed recently, clear any cached config so Laravel reads the new one:
php artisan config:clear
Check the model's table name
If Eloquent guesses the wrong table name, set it explicitly:
class Customer extends Model
{
protected $table = 'customers';
}
See environment variables in Laravel for how the connection is configured.
Subscribe to our newsletter
Do you want to receive regular updates with fresh and exclusive content to learn more about web development, hosting, security and performance? Subscribe now!
Related articles
Stream MySQL backup directly to S3 bucket
This MySQL error means your query references a table that does not exist in the connected database. In Laravel it almost always means migrations have not run, or you are connected to the wrong database.
Export MySQL database using command line
This MySQL error means your query references a table that does not exist in the connected database. In Laravel it almost always means migrations have not run, or you are connected to the wrong database.