Php 是否可以在没有订单的情况下迁移迁移?(如果没有,我如何解决此问题)
对我来说,描述我的问题和解决方案的最好方式就是这个链接 我的问题就是这个,解决方案实际上是可行的,但在我的情况下,要么我有一个替代方案,要么我的模式生成器出了问题,我需要更好地理解它 我的代码基本上是这样的:Php 是否可以在没有订单的情况下迁移迁移?(如果没有,我如何解决此问题),php,database,laravel,migration,schema,Php,Database,Laravel,Migration,Schema,对我来说,描述我的问题和解决方案的最好方式就是这个链接 我的问题就是这个,解决方案实际上是可行的,但在我的情况下,要么我有一个替代方案,要么我的模式生成器出了问题,我需要更好地理解它 我的代码基本上是这样的: //just an example, not my code Schema A (as) //other code, such as table->increments('id') $table->unsignedInteger('b_id'); $table->
//just an example, not my code
Schema A (as)
//other code, such as table->increments('id')
$table->unsignedInteger('b_id');
$table->unsignedInteger('c_id');
$table->foreign('b_id')->references('id')->on('bs');
$table->foreign('c_id')->references('id')->on('cs');
Schema B (bs)
$table->unsignedInteger('a_id');
$table->unsignedInteger('c_id');
$table->foreign('a_id')->references('id')->on('as');
$table->foreign('c_id')->references('id')->on('cs');
Schema C (cs)
$table->unsignedInteger('a_id');
$table->unsignedInteger('b_id');
$table->foreign('a_id')->references('id')->on('as');
$table->foreign('b_id')->references('id')->on('bs');
所以这两个订单都不能帮助我解决这个问题
我的情况是否有解决方案,或者我的代码/模式逻辑错误,需要修改代码?在Laravel>=5.0中,实现这一点的一种方法是在正确命名的迁移文件夹中使用某些脚本。就像我过去在Sprint中进行迁移一样
——迁移/
---冲刺8/
------user_table.php
------car_table.php
--冲刺9/
------投诉表格.php
------supervisor_table.php
使用这种方法,您必须在每个子文件夹上运行migration命令:
php artisan迁移--path=/database/migrations/Sprint8
php artisan migrate--path=/database/migrations/Sprint9
但是,您可以轻松地扩展artisan系统,编写自己的migrate命令,该命令将遍历migrations文件夹下的所有文件夹,为您创建并运行这些命令
如果您不想通过artisan进行此操作,也可以简单地编写一个shell脚本
A
,B
,C
$table->increments('id');
// some other columns
$table->increments('id');
// some other columns
$table->increments('id');
// some other columns
$table->unsignedInteger('b_id');
$table->unsignedInteger('c_id');
$table->foreign('b_id')->references('id')->on('B');
$table->foreign('c_id')->references('id')->on('C');
$table->unsignedInteger('a_id');
$table->unsignedInteger('c_id');
$table->foreign('a_id')->references('id')->on('A');
$table->foreign('c_id')->references('id')->on('C');
$table->unsignedInteger('a_id');
$table->unsignedInteger('b_id');
$table->foreign('a_id')->references('id')->on('A');
$table->foreign('b_id')->references('id')->on('B');
模式B:
$table->increments('id');
// some other columns
$table->increments('id');
// some other columns
$table->increments('id');
// some other columns
$table->unsignedInteger('b_id');
$table->unsignedInteger('c_id');
$table->foreign('b_id')->references('id')->on('B');
$table->foreign('c_id')->references('id')->on('C');
$table->unsignedInteger('a_id');
$table->unsignedInteger('c_id');
$table->foreign('a_id')->references('id')->on('A');
$table->foreign('c_id')->references('id')->on('C');
$table->unsignedInteger('a_id');
$table->unsignedInteger('b_id');
$table->foreign('a_id')->references('id')->on('A');
$table->foreign('b_id')->references('id')->on('B');
模式C:
$table->increments('id');
// some other columns
$table->increments('id');
// some other columns
$table->increments('id');
// some other columns
$table->unsignedInteger('b_id');
$table->unsignedInteger('c_id');
$table->foreign('b_id')->references('id')->on('B');
$table->foreign('c_id')->references('id')->on('C');
$table->unsignedInteger('a_id');
$table->unsignedInteger('c_id');
$table->foreign('a_id')->references('id')->on('A');
$table->foreign('c_id')->references('id')->on('C');
$table->unsignedInteger('a_id');
$table->unsignedInteger('b_id');
$table->foreign('a_id')->references('id')->on('A');
$table->foreign('b_id')->references('id')->on('B');
- 现在,创建子表,换句话说,这些是描述关系的中间表,您可以使用pivot属性访问它们
$table->increments('id');
// some other columns
$table->increments('id');
// some other columns
$table->increments('id');
// some other columns
$table->unsignedInteger('b_id');
$table->unsignedInteger('c_id');
$table->foreign('b_id')->references('id')->on('B');
$table->foreign('c_id')->references('id')->on('C');
$table->unsignedInteger('a_id');
$table->unsignedInteger('c_id');
$table->foreign('a_id')->references('id')->on('A');
$table->foreign('c_id')->references('id')->on('C');
$table->unsignedInteger('a_id');
$table->unsignedInteger('b_id');
$table->foreign('a_id')->references('id')->on('A');
$table->foreign('b_id')->references('id')->on('B');
模式BS:
$table->increments('id');
// some other columns
$table->increments('id');
// some other columns
$table->increments('id');
// some other columns
$table->unsignedInteger('b_id');
$table->unsignedInteger('c_id');
$table->foreign('b_id')->references('id')->on('B');
$table->foreign('c_id')->references('id')->on('C');
$table->unsignedInteger('a_id');
$table->unsignedInteger('c_id');
$table->foreign('a_id')->references('id')->on('A');
$table->foreign('c_id')->references('id')->on('C');
$table->unsignedInteger('a_id');
$table->unsignedInteger('b_id');
$table->foreign('a_id')->references('id')->on('A');
$table->foreign('b_id')->references('id')->on('B');
架构CS:
$table->increments('id');
// some other columns
$table->increments('id');
// some other columns
$table->increments('id');
// some other columns
$table->unsignedInteger('b_id');
$table->unsignedInteger('c_id');
$table->foreign('b_id')->references('id')->on('B');
$table->foreign('c_id')->references('id')->on('C');
$table->unsignedInteger('a_id');
$table->unsignedInteger('c_id');
$table->foreign('a_id')->references('id')->on('A');
$table->foreign('c_id')->references('id')->on('C');
$table->unsignedInteger('a_id');
$table->unsignedInteger('b_id');
$table->foreign('a_id')->references('id')->on('A');
$table->foreign('b_id')->references('id')->on('B');
- 现在,您可以按此顺序成功运行迁移,您应该可以开始了