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.
- Check ServiceProviders' boot function if it contains queries that are querying tables that don't exist.
- 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
How to Set a Default Attribute Value for a Laravel/Eloquent Model
Parse JSON String Contents into PHP Array
Why Is It Whenever I Use Scandir() I Receive Periods at the Beginning of the Array
Utf-8 Character Encoding Battles JSON_Encode()
Will Xpath 2.0 And/Or Xslt 2.0 Be Implemented in PHP
How to Change PHP's Eregi to Preg_Match
Echo Menu Tree with Recursive Function
Clean Links to PHP-Generated JavaScript and CSS
Hide Variable Product Dropdown That Has a Unique Variation Selected by Default in Woocommerce
How to Automatically Detect User's Timezone
Function to Return Only Alpha-Numeric Characters from String
PHP Function Use Variable from Outside
Save PHP Variables to a Text File