tattooedgeek
tattooedgeek

Reputation: 518

laravel 4 multiple DB connection

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. :)

Upvotes: 3

Views: 3600

Answers (2)

forgandenny
forgandenny

Reputation: 21

It worked with

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

but it has ignored

Schema::connection('my_connection_name').

Upvotes: 2

Deinumite
Deinumite

Reputation: 4019

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');
});

Upvotes: 4

Related Questions