Overriding Default Laravel database configuration for artisan migrate commands

半世苍凉 提交于 2019-12-03 17:28:40

You may use:

php artisan migrate:install --database=seconddb

but you need to have defined this seconddb connection in your database.php config file. Of course running this command you will only create migrations table, nothing more, so if you want to make standard migration you need to use:

php artisan migrate --database=seconddb

and for seeding:

php artisan db:seed --database=seconddb

Example database.php file configuration:

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

'seconddb' => array(
    'driver'    => 'mysql',
    'host'      => 'localhost',
    'database'  => 'otherdb',
    'username'  => 'user',
    'password'  => 'otherpass',
    'charset'   => 'utf8',
    'collation' => 'utf8_unicode_ci',
    'prefix'    => '',
),

And in case you need other information about paramters, you can always run --help argument for example:

php artisan migrate:install --help
php artisan migrate --help

Would adding a new DB in the settings file help? Perhaps:

    # Slightly different database connection
    'mydbadmin' => array(
        'driver'    => 'mysql',
        'host'      => 'host1',
        'database'  => 'mydb',
        'username'  => 'mydbadmin',
        'password'  => 'ultrasecret password'
        'charset'   => 'utf8',
        'collation' => 'utf8_unicode_ci',
        'prefix'    => '',
    ),

then specify that database within the CLI, e.g.

php artisan migrate:install --database['mydbadmin']
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!