Use php artisan config:clear (not cache)
Feb 17, 2020
11
Level 18
Wrong default DB connection
I have a problem with config/database.php. My app connects with multiple databases as seen below.
return [
/*
|--------------------------------------------------------------------------
| PDO Fetch Style
|--------------------------------------------------------------------------
|
| By default, database results will be returned as instances of the PHP
| stdClass object; however, you may desire to retrieve records in an
| array format for simplicity. Here you can tweak the fetch style.
|
*/
'fetch' => PDO::FETCH_CLASS,
/*
|--------------------------------------------------------------------------
| Default Database Connection Name
|--------------------------------------------------------------------------
|
| Here you may specify which of the database connections below you wish
| to use as your default connection for all database work. Of course
| you may use many connections at once using the Database library.
|
*/
'default' => env('DB_CONNECTION', 'mysql'),
'connections' => [
'mysql' => [
'driver' => 'mysql',
'host' => env('DB_HOST', 'localhost'),
'port' => env('DB_PORT', 3306),
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'charset' => env('DB_CHARSET', 'utf8'),
'collation' => env('DB_COLLATION', 'utf8_unicode_ci'),
'prefix' => env('DB_PREFIX', ''),
//'timezone' => env('DB_TIMEZONE', '+00:00'),
'strict' => env('DB_STRICT_MODE', false),
],
'mysql_wms' => [
'driver' => 'mysql',
'host' => env('DB_HOST', 'localhost'),
'database' => env('DB_DATABASE_WMS', 'forge'),
'username' => env('DB_USERNAME_WMS', 'forge'),
'password' => env('DB_PASSWORD_WMS', ''),
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
'strict' => false,
],
],
So the problem is that when i run php artisan migrate the application use as default the mysql_wms instead of mysql. Also when i run config('database.default) on tinker it returns mysql_wms.
- I have already checked my env and is correct DB_CONNECTION=mysql
- I have already run php artisan cache:clear
- I also assign to default connection the db without use env variable. ( 'default' => 'mysql' )
Please or to participate in this conversation.