Laravel Migration Unknown database [1049]

Viewed 768

I'm trying to use xampp for my sql server, everything works fine on that part (I can access phpmyadmin, create my db, etc). However, when I run the command "php artisan migrate" it always says te following error:

Illuminate\Database\QueryException 

  SQLSTATE[HY000] [1049] Unknown database 'inverdana' (SQL: select * from information_schema.tables where table_schema = inverdana and table_name = migrations and table_type = 'BASE TABLE')

I have tried clearing cache, restarting the laravel server, modifying the .env file to use the address XAMPP gives, but nothing works.

It's really frustrating that laravel doesn't gives more clues on what's failing.

4 Answers

It turned out to be the operating system (I'm using MacOS). In case someone else is facing the same problem you might want to try what helped me.

The problem was that I had installed mysql and apache from my terminal. This caused that XAMPP wasn't able to initialize properly and didn't share the proper ports, therefore, my Laravel application could never find the right database. So I uninstalled both mysql, apache and I reinstalled XAMPP (version 7.4.5).

After that, everything worked properly.

Another Issue could be that your configurations are already cached and saved in /bootstrap/cache/config.php file. You just need to delete this file and your problem is sorted. if you want them to be cached again then run

php artisan config:cache

command

In my case,

  • step 1: clear logs from laravel.log
  • step 2: php artisan optimize
  • step 3: php artisan migrate

Try this,

  • Step 1: clear logs from laravel.log
  • Step 2: php artisan optimize
  • Step 3: php artisan migrate

This command will clear all kinds of cache at once. :

$ php artisan optimize:clear

This is an alias of :

$ php artisan view:clear
$ php artisan config:clear
$ php artisan route:clear
$ php artisan cache:clear
$ php artisan clear-compiled

Is it possible to use the code below with the new clear cache commands:

//Clear Cache facade value:
Route::get('/clear-cache', function() {
    $exitCode = Artisan::call('cache:clear');
    return '<h1>Cache facade value cleared</h1>';
});

//Reoptimized class loader:
Route::get('/optimize', function() {
    $exitCode = Artisan::call('optimize');
    return '<h1>Reoptimized class loader</h1>';
});

//Route cache:
Route::get('/route-cache', function() {
    $exitCode = Artisan::call('route:cache');
    return '<h1>Routes cached</h1>';
});

//Clear Route cache:
Route::get('/route-clear', function() {
    $exitCode = Artisan::call('route:clear');
    return '<h1>Route cache cleared</h1>';
});

//Clear View cache:
Route::get('/view-clear', function() {
    $exitCode = Artisan::call('view:clear');
    return '<h1>View cache cleared</h1>';
});

//Clear Config cache:
Route::get('/config-cache', function() {
    $exitCode = Artisan::call('config:cache');
    return '<h1>Clear Config cleared</h1>';
});
Related