Page 1 of 1

laravel: migrate table to specific database

Posted: Wed Dec 09, 2015 8:14 am
by publicGenome
Hello There,

I'm working on laravel4.2

I created a migration file as:

Code: Select all

php artisan migrate:make create_sample_group --create=sample_group --path=app/database/migrations/illumina/
Before running the above command I create folder illumina in app/migration

After running the migrate command, I can see file as 2015_12_09_084943_create_sample_group.php
That is today's name, etc

I make a, b, c changes for column names in it. And would like to create respective table which can be done by:

Code: Select all

artisan migrate
But I'd like to specify to which database laravel should create this table. Is there a way to do so?

My database.php looks like:

Code: Select all


'default' => 'alpha',

'connections' => array(
'alpha' => array(
            'driver' => 'mysql',
            'host' => 'localhost',
            'database' => 'alpha_1',
            'username' => 'root', 
            'password' => '',
            'charset' => 'utf8',
            'collation' => 'utf8_unicode_ci',
            'prefix' => '',
        ),

        'pqr_1' => array(
            'driver' => 'mysql',
            'host' => 'localhost',
            'database' => 'pqr',
            'username' => 'root', //      
            'password' => '',
            'charset' => 'utf8',
            'collation' => 'utf8_unicode_ci',
            'prefix' => '',
        ),
//and so on multiple databases 
////
)

I'd like to create table in database pqr_1

I don't see documentation of it at

http://laravel.com/docs/4.2/migrations# ... migrations
Looking forward for guidance.

Re: laravel: migrate table to specific database

Posted: Wed Dec 09, 2015 9:15 am
by publicGenome
Update:

I figured this out:

Code: Select all

php artisan migrate --path=app/database/migrations/illumina/ --database=pqr_1
Here:
Path refers to the directory where files are located which you'd like to run. That is which table to be created.

Database - has to be same name as it is in database.php
pqr_1 - maps to say beta database; then table will be created in beta database.

Documentation says you can specify connection as:

Code: Select all

Schema::connection('foo')->create (blah blah )
However, this didn't work for me. I got message as:
Nothing to migrate.
Thanks

Re: laravel: migrate table to specific database

Posted: Mon Feb 08, 2016 10:34 pm
by Swhite
Hey,I'm sharing a link just check this " http://www.sitepoint.com/laravel-migrations/ ".

Hope you find it relevant.
Good luck