Can I place two migration tables in different databases when using Laravel?

北城余情 提交于 2019-12-24 21:27:08

问题


Right now I am building few social networks each having its own domain and database called content and a single common user database that is connected to all of them.

The question is - can I place the migration data concerning users into the users' database, so that every time updates to database are implemented via

php artisan migrate

on each of the social networks, - those would only apply to user database only once.


回答1:


I have done this on a project in the past, but you need to be careful with the Artisan commands you run.

Working with your example I would do the following;

  • app/database/migrations/users - Migrations for your user database live here
  • app/database/migrations/content - Migrations for your content database live here

You will also need to create appropriate database connections to your config;

In app/config/database.php;

<?php
return [
    'connections' => [
        'users' => [
            // Usual database connection details here
        ],
        'content_site1' => [
            // Usual database connection details here
        ],
        'content_site2' => [
            // Usual database connection details here
        ]
    ]
];

Once you have this all configured you should be able to run php artisan migrate --path app/database/migrations/users --database users to migrate your users database, and php artisan migrate --path app/database/migrations/content --database content_site1 for your content site. Remember change the database param for each connection you want to run the migration on.



来源:https://stackoverflow.com/questions/28339663/can-i-place-two-migration-tables-in-different-databases-when-using-laravel

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