How to Fix the "Base Table or View Not Found: 1146" Error When Running 'PHP Artisan Migrate' Command

How to fix the Table doesn't exist error error when running 'php artisan migrate' command?

The error usually throw when database doesn't exist in mysql.

But in your case, database exists in mysql server.So you it look like your application executing select query in any one of the service provider boot() method

public function boot()
{

}

So you might need to stop query execution till migration completes.

Laravel 8 SQLSTATE[42S02]: Base table or view not found: 1146 Table even though I am trying to create this table

if you want to create a table with migration, you need to use ::create() instead of ::table()

::table() function tries to alter your table

Can't start Laravel, I get Base table or view not found error

If you encounter with this problem and if it's not caused by migration files then most probably it happens because of 2 possible reasons.

  1. Check ServiceProviders' boot function if it contains queries that are querying tables that don't exist.
  2. Check if you've created custom helper function and autoloaded that helper function in composer.json file. If custom helper function contains queries that are querying tables that don't exist it will cause this error.

Since ServiceProviders' boot functions and autoloaded custom helper functions are loaded first when laravel is started all the php artisan commands will generate "Base table or view not found" error.

At this point what you should do is comment out those queries that are querying nonexistent tables and run php artisan serve then run php artisan migrate. Then uncomment those lines, save it and everything should work fine.

As @devk suggested it's better to check laravel log files which points exactly to where the problem happens. It led me to find a solution.
For this don't forget to Turn on debug mode.



Related Topics



Leave a reply



Submit