laravel 4多个DB连接
问题描述:
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. :)
答
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');
});
答
It worked with
php artisan migrate --env=local --database=my_connection_name
but it has ignored
Schema::connection('my_connection_name').