0

I have 2 databases so I work under 2 different migration folders. I choose path, which works fine.

php artisan migrate --path="database/migrations/game"

I added a new connection next to the existing mysql connection in config/database.php:

'mysql' => [ ....default connection ]

'mysql_game_base' => [
   'driver' => 'mysql',
   'host' => env('DB_HOST', '127.0.0.1'),....bla bla

And than I added this connection as follows in my migration folder:

Schema::connection("mysql_game_base")->create('players', function (Blueprint $table) {
        $table->increments('id');
        $table->string("name");
        $table->timestamps();
    });

But the migration process keeps creating all tables into the default connection.

I also tried to add a database parameter, but still no chance:

php artisan migrate --path="database/migrations/game" --database="mysql_game_base"
tolga
  • 2,462
  • 4
  • 31
  • 57
  • 1
    does this question helps you? https://stackoverflow.com/questions/25952348/laravel-run-migrations-on-another-database – Erubiel Aug 19 '18 at 19:58
  • 1
    I was looking for the same thing so I added a new env variable and changed the mysql connection settings. This helped. Thank you. – tolga Aug 19 '18 at 19:59

1 Answers1

2

I found the solution. When I was creating the second connection variable, I should also define a new variable in .env file.

DB_DATABASE=my_db
DB_DATABASE_GAME=my_db_game

Than I should have used this in database config:

'database' => env('DB_DATABASE_GAME', 'my_db_game'),

The confusion comes from defining in two different places.

tolga
  • 2,462
  • 4
  • 31
  • 57