Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I specify which database connection Laravel uses for the migration table?

I'm working on an app with multiple database connections. It seems when I run php artisan migrate:install it always creates the migrations table using my default connection in app/config/database.php, which is not ideal.

Is there a way to specify a different connection for the migrations table itself?

like image 477
aesterisk Avatar asked Aug 21 '14 21:08

aesterisk


People also ask

How set DB connection in Laravel?

Laravel makes connecting with databases and running queries extremely simple. The database configuration file is app/config/database. php . In this file you may define all of your database connections, as well as specify which connection should be used by default.

How check Laravel database connected or not?

Echo the Laravel database name in Blade/PHP The simplest way it to place the following script in a Blade or PHP file. This will output the name of the database or return 'none' if there is no connection. If you view it in the browser, it gives you the name of the connected database.

How do I run a specific migration in Laravel?

To run the specific migration in Laravel, you need to use --path option with the php artisan migrate command. Let's take a simple example, we have '2019_12_04_131405_create_payments_table. php' migration in the database/migrations directory and we would like to run this migration.


2 Answers

Update

For anyone with a similar question, I found a better answer.

Looks like you can't specify the connection from a config file or anything, but you can when you run migrate from the command line...

php artisan migrate:install --database=NAME_OF_CONNECTION

There is one caveat: anytime you run an actual migration you must also specify the database connection with --database again or it will re-create the migrations table using the default connection.

like image 169
aesterisk Avatar answered Sep 28 '22 05:09

aesterisk


Edit: Looks like you want to change where the migrations table is stored. This I believe always uses the default. You can however specify where a table is supposed to be created as below:

You can specify a connection like so:

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

From http://laravel.com/docs/schema

like image 37
nesl247 Avatar answered Sep 28 '22 05:09

nesl247