I have this error when i use php artisan migrate in my Laravel project.
[PDOException]
SQLSTATE[HY000] [1049] Unknown database 'previous_db_name'
this is my database.php file :
'default' => env('DB_CONNECTION', 'mysql'),
'connections' => [
    'mysql' => [
        'driver'    => 'mysql',
        'host'      => env('DB_HOST', 'localhost'),
        'database'  => env('DB_DATABASE', 'current_db_name'),
        'username'  => env('DB_USERNAME', 'root'),
        'password'  => env('DB_PASSWORD', ''),
        'charset'   => 'utf8',
        'collation' => 'utf8_unicode_ci',
        'prefix'    => '',
        'strict'    => false,
    ],
],
I saw this error in this question and this question but none of them was not helpful.
It clearly mentions that there's no such database named previous_db_name.
From what it seems the database.php file is not where the variable is from.
Check the .env file in your Laravel installation folder to see if that's the database name that you have wrongly specified.
Please run this command:
php artisan config:cache
                        php artisan cache:clear
AND
restart your server
I had to kill my server and re-run php artisan serve for my project to register the change of my DB_DATABASE name.  I kept getting the error even after clearing the cache because I didn't realize this.
In Laravel 5.x You should define the DB Details in two files
.env file in the project folder.database.php file inside config folderIf you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With