1

I am new to laravel. why does my laravel project keep connecting with the old database?

I tried to clear cache but nothing works for me php artisan config: cache

my env file is connected with the new database but shows error on terminal saying

Unknown database 'admin'

miken32
  • 42,008
  • 16
  • 111
  • 154

2 Answers2

2

If you use php artisan config: cache, it will create a config.php file under cache in your bootstrap folder.
So, If you change something in your .env file, it will not be updated in your cache config.php file.
Then, when you run php artisan config:clear, the new changes will be updated in your cache config.php file. That's why you are facing this problem.

To overcome this, try the following

  1. delete the config.php file from cache folder inside bootstrap folder.
  2. Run composer update.

I too faced issues like this, when I did the above steps, It solved.

Udhav Sarvaiya
  • 9,380
  • 13
  • 53
  • 64
Nandy
  • 92
  • 5
-1

Hope your database credentials are correct in a .env file:

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=            // Your Database Name
DB_USERNAME=           // Your Database Username
DB_PASSWORD=          // Your Database Password

If All is correct then After completion of .env edit, You can clear the configuration cache with the following artisan command: php artisan config:cache


Also, check in config/database.php, Check that the old database name has not been used on it

Also, If you are using the PHP's default web server (eg. php artisan serve) you need to restart your server after changing your .env file values.

Udhav Sarvaiya
  • 9,380
  • 13
  • 53
  • 64