laravel: migrate table to specific database

Discussion for various published PHP frameworks, including Zend Framework, CodeIgniter, Kohana, CakePHP, Yii, Symfony, and others.

Moderator: General Moderators

Post Reply
publicGenome
Forum Contributor
Posts: 110
Joined: Thu Apr 16, 2015 7:55 am

laravel: migrate table to specific database

Post 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.
publicGenome
Forum Contributor
Posts: 110
Joined: Thu Apr 16, 2015 7:55 am

Re: laravel: migrate table to specific database

Post 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
Swhite
Forum Newbie
Posts: 7
Joined: Thu Feb 04, 2016 1:19 am

Re: laravel: migrate table to specific database

Post by Swhite »

Hey,I'm sharing a link just check this " http://www.sitepoint.com/laravel-migrations/ ".

Hope you find it relevant.
Good luck
Post Reply