Database [] not configured - Laravel

5.1k views Asked by At

I have searched a lot about it and tried every possible solution I could find or think of.

So I am changing database configuration to a new database as follows:

DB::disconnect('mysql');
config(['database.connections.mysql.database' => $new_db_name]);

If i try to get the database name like:

dd(config('database.connections.mysql.database'));

I get the right database name which I just set. But when i try to run migration on it:

\Artisan::call('migrate', ['--database' => $new_db_name ]);

I get the error : Database [$new_db_name] not configured

Any help is appreciated.

1

There are 1 answers

1
Marcin Nabiałek On BEST ANSWER

The problem is that --database parameter is quite confusing. It shouldn't hold database name but database connection name, so in your case:

\Artisan::call('migrate', ['--database' => 'mysql' ]);

should do the trick.