13

I am trying to set up a multiple database application in laravel 5. I have a database A and a second database B. In database A there are my main models. Now I tried to write a migration file that creates a new table in database B. This works, because I can set the connection to database B in the schema builder like this:

Schema::connection('foo')->create('users', function (Blueprint $table) {
    $table->increments('id'); 
});

But the problem here is, that the migrations table is still in database A. I want to have a migrations table in database A for all of the tables which are in database A and another migrations table in database B for all of the tables which are in database B.

I am searching for something like this:

Schema::connection('foo')->migrations_table_connection('foo')->create('users', function (Blueprint $table) {
    $table->increments('id'); 
});

Is there any way to do that? THX

Phil
  • 595
  • 1
  • 3
  • 14

1 Answers1

24

I found it out with the help of this Use one Laravel migrations table per database and post the answer here for others.

In order to separate the migrations you need to run the migrate command with the database option like this:

php artisan migrate --database="nameOfConnection"
Community
  • 1
  • 1
Phil
  • 595
  • 1
  • 3
  • 14
  • 1
    what if you have several databases as secondary, for e.g. a situation where you have one main database with a table of fiscal-years and for each fiscal-year record you have a separate database... in that case, how would you go around running migrations in all the fiscal-year tables? – M.Imran Mamda Oct 21 '19 at 15:56