具有多个迁移表的 Laravel 多个数据库
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/42503780/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
laravel multiple databases with multiple migration tables
提问by Phil
I am trying to set up a multiple database application in laravel 5. I have a database A and a second database B. In database A there are my main models. Now I tried to write a migration file that creates a new table in database B. This works, because I can set the connection to database B in the schema builder like this:
我正在尝试在 laravel 5 中设置一个多数据库应用程序。我有一个数据库 A 和第二个数据库 B。在数据库 A 中有我的主要模型。现在我尝试编写一个在数据库 B 中创建一个新表的迁移文件。这是有效的,因为我可以像这样在模式构建器中设置到数据库 B 的连接:
Schema::connection('foo')->create('users', function (Blueprint $table) {
$table->increments('id');
});
But the problem here is, that the migrations table is still in database A. I want to have a migrations table in database A for all of the tables which are in database A and another migrations table in database B for all of the tables which are in database B.
但这里的问题是,迁移表仍然在数据库 A 中。我想在数据库 A 中有一个迁移表,用于数据库 A 中的所有表和数据库 B 中的另一个迁移表,用于所有表在数据库 B 中。
I am searching for something like this:
我正在寻找这样的东西:
Schema::connection('foo')->migrations_table_connection('foo')->create('users', function (Blueprint $table) {
$table->increments('id');
});
Is there any way to do that? THX
有没有办法做到这一点?谢谢
回答by Phil
I found it out with the help of this Use one Laravel migrations table per databaseand post the answer here for others.
我在这个为每个数据库使用一个 Laravel 迁移表的帮助下找到了它,并在此处为其他人发布了答案。
In order to separate the migrations you need to run the migrate command with the database option like this:
为了分离迁移,您需要使用数据库选项运行 migrate 命令,如下所示:
php artisan migrate --database="nameOfConnection"