使用Laravel时可以将两个迁移表放置在不同的数据库中吗? [英] Can I place two migration tables in different databases when using Laravel?

查看:65
本文介绍了使用Laravel时可以将两个迁移表放置在不同的数据库中吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

现在,我正在构建几个社交网络,每个社交网络都有自己的域和称为内容的数据库,以及与所有社交网络相连的单个公共用户数据库.

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迁移

php artisan migrate

在每个社交网络上,-这些社交网络仅适用于用户数据库一次.

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

推荐答案

我过去在一个项目上完成过此操作,但是您需要谨慎使用所运行的Artisan命令.

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-您的用户数据库的迁移在此处
  • app/database/migrations/content-您的内容数据库的迁移在此处
  • 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;

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
        ]
    ]
];

完成所有这些配置后,您应该能够运行php artisan migrate --path app/database/migrations/users --database users来迁移用户数据库,并运行php artisan migrate --path app/database/migrations/content --database content_site1来访问内容站点.切记为要在其上进行迁移的每个连接更改数据库参数.

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.

这篇关于使用Laravel时可以将两个迁移表放置在不同的数据库中吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆