Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/database/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 是否可以在没有订单的情况下迁移迁移?(如果没有,我如何解决此问题)_Php_Database_Laravel_Migration_Schema - Fatal编程技术网

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

  • 模式A:

    $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');
    
    • 现在,您可以按此顺序成功运行迁移,您应该可以开始了

    请编辑您的问题并添加您创建架构的方式,我们无法帮助您了解这些信息。Laravel迁移是从最早的迁移到最新的迁移。您需要在逻辑上重新排列迁移文件。我不明白为什么userSchema引用了这两个表。你能发布你的迁移文件吗?我编辑了我的帖子,它仍然不是我真正的代码,但我真正的代码很长,逻辑基本相同。现在我想两个相互引用的模式不是一个好主意,这就是为什么我在挣扎?