3

Playing around with laravel 4 and was wondering if there is a way to run migrations on different connections, so if I have as default:

'sqlsrv' => array(
    'driver'   => 'sqlsrv',
    'host'     => '192.168.1.11\SQLEXPRESS',
    'database' => 'database1',
    'username' => 'sa',
    'password' => 'password',
    'prefix'   => '',
    ),

But I want a different migration to go here:

'sqlsrv2' => array(
    'driver'   => 'sqlsrv',
    'host'     => '192.168.1.11\SQLEXPRESS',
    'database' => 'database2',
    'username' => 'sa',
    'password' => 'password',
    'prefix'   => '',
    ),

I have no doubt there is a way to do it, but I'm not finding it in the docs. :)

1
  • Besides specifying your connection directly into the migration like Schema::connection('foo')->create... your other option is to extend the Migration and specify it there. I agree it sucks that you can't specify the connection during the migrate command. Commented Nov 18, 2015 at 21:57

2 Answers 2

4

From the docs at http://laravel.com/docs/schema#creating-and-dropping-tables

To specify which connection the schema operation should take place on, use the Schema::connection method:

Schema::connection('foo')->create('users', function($table)
{
    $table->increments('id');
});
Sign up to request clarification or add additional context in comments.

1 Comment

Holy crap I looked at that 10 times and it just now makes sense.. Thanks man.
2

It worked with

php artisan migrate --env=local --database=my_connection_name

but it has ignored

Schema::connection('my_connection_name').

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.