I am using xampp on windows 10. I have multiple laravel 5.2 projects on this machine. When I am executing Project 1 it gives me the error that database_project_1.table_of_project_2
table or view do not exist, but the table table_of_project_2
is existing in the database_project_2
. This issue comes rarely.
Below is the Project 1 .env file
APP_ENV=local
APP_DEBUG=true
APP_KEY=base64:ratSluNv930gb3wp1UOabW6Ze3jEJn3ixtTX/wgqYZc=
APP_URL=http://project-1.dev/
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=database_project_1
DB_USERNAME=root
DB_PASSWORD=j@yshr33r@m
Below is the Project 2 .env file
APP_ENV=local
APP_DEBUG=true
APP_KEY=base64:XRgQHfYiKPmHtHZ5UbX38KDlBnl/nyBSt+8qnkOISTg=
APP_URL=http://project-2.dev/
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=database_project_2
DB_USERNAME=root
DB_PASSWORD=j@yshr33r@m
I have tried below commands but with no luck:
php artisan config:clear
php artisan cache:clear
Please check the screenshot below:
Please let me know if any thing is missing.
Here is the config/database.php
code for both projects.
Project 1 config/database.php
<?php
return [
'fetch' => PDO::FETCH_CLASS,
'default' => env('DB_CONNECTION', 'mysql'),
'connections' => [
'mysql' => [
'driver' => 'mysql',
'host' => env('DB_HOST', 'localhost'),
'port' => env('DB_PORT', '3306'),
'database' => env('DB_DATABASE', 'database_project_1'),
'username' => env('DB_USERNAME', 'root'),
'password' => env('DB_PASSWORD', 'j@yshr33r@m'),
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
'strict' => false,
'engine' => null,
],
],
'migrations' => 'migrations',
'redis' => [
'cluster' => false,
'default' => [
'host' => env('REDIS_HOST', 'localhost'),
'password' => env('REDIS_PASSWORD', null),
'port' => env('REDIS_PORT', 6379),
'database' => 0,
],
],
];
Project 2 config/database.php
<?php
return [
'fetch' => PDO::FETCH_CLASS,
'default' => env('DB_CONNECTION', 'mysql'),
'connections' => [
'mysql' => [
'driver' => 'mysql',
'host' => env('DB_HOST', 'localhost'),
'port' => env('DB_PORT', '3306'),
'database' => env('DB_DATABASE', 'database_project_2'),
'username' => env('DB_USERNAME', 'root'),
'password' => env('DB_PASSWORD', 'j@yshr33r@m'),
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
'strict' => false,
'engine' => null,
],
],
'migrations' => 'migrations',
'redis' => [
'cluster' => false,
'default' => [
'host' => env('REDIS_HOST', 'localhost'),
'password' => env('REDIS_PASSWORD', null),
'port' => env('REDIS_PORT', 6379),
'database' => 0,
],
],
];
Take a look at the code and let me know anything required.
Is it problem with reading .env
file or conflicting .env
file of another project?
You have specified to use database_project_1
in Project 2's config/database.php
:
'database' => env('DB_DATABASE', 'database_project_1'),
So if ever env('DB_DATABASE')
does not return a value , the default of database_project_1
will be used. That can happen depending on caching, as described in a few questions here on SO: example 1, example 2, example 3.
If it is a caching issue, you can try to fix that by some combination of the following (varies between installs and versions):
php artisan config:clear
php artisan cache:clear
composer dump-autoload
// restart your web server
But surely the simplest fix would be to just use the correct default value in your Project 2 config/database.php
:
'database' => env('DB_DATABASE', 'database_project_2'),
If 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