Ganesh
Ganesh

Reputation: 25

Laravel Database migration procedure

I am currently using Laravel 5.4. I have a separate database per client. I would like to run database migrations in all my client databases. The database names are in the format of clientdb_{clientid}. I have tried using

Config::set("database.connections.mysql", ["database" =>
 "clientdb_".$client['id'],
"username" => "root","password" => ""]);

 $this->callSilent('migrate', 
[ '--path' => 'database/migrations/clients','--database'=>'clientdb_'.$client['id']]);

but I am getting exception called

[InvalidArgumentException] Database [clientdb_1] not configured.

Upvotes: 0

Views: 143

Answers (2)

Don't Panic
Don't Panic

Reputation: 14520

The code you show is configuring the connection labelled mysql. I think what you are really trying to do is configure a new database connection called clientdb_1:

Config::set("database.connections.clientdb_" . $client['id'], [
    "database" => "clientdb_" . $client['id'],
    "username" => "root",
    "password" => ""
]);

Upvotes: 1

user223321
user223321

Reputation: 153

Looks like the database is not configured in your config/database.php file

Upvotes: 0

Related Questions