Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/laravel/10.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
Mysql Laravel:使用外键进行迁移_Mysql_Laravel - Fatal编程技术网

Mysql Laravel:使用外键进行迁移

Mysql Laravel:使用外键进行迁移,mysql,laravel,Mysql,Laravel,我知道这个问题已经被问了很多次了,但我尝试了所有的解决方案,它仍然给我一个错误 我想迁移我的表: class CreateFichesTable extends Migration { public function up() { Schema::create('fiches', function (Blueprint $table) { $table->engine = 'InnoDB'; $table->increments('id');

我知道这个问题已经被问了很多次了,但我尝试了所有的解决方案,它仍然给我一个错误

我想迁移我的表:

class CreateFichesTable extends Migration
{

public function up()
{
    Schema::create('fiches', function (Blueprint $table) {
        $table->engine = 'InnoDB';
        $table->increments('id');
        $table->string('type');
        $table->string('nom');
        $table->string('description');
        $table->string('image');
        $table->integer('equipe_id')->unsigned();
        $table->timestamps();
    });

    Schema::table('fiches', function(Blueprint $table)
    {
        $table->foreign('equipe_id')->references('id')->on('equipes');
    });
}
}

}

我得到:

Exception trace:

1   PDOException::("SQLSTATE[HY000]: General error: 1215 Cannot add foreign 
key constraint")
我试图强制使用引擎“InnoDB”,但仍然不起作用


有什么提示吗?

当您创建新的迁移文件时,laravel会自动添加到开始日期时间中,如图所示
2018\u 08\u 10\u 111004\u
,以检测必须首先创建哪个迁移。正如您在注释中所显示的,您的迁移文件是
2018\u 08\u 31\u 141536\u create\u fiches\u table.php
2018\u 09\u 03\u 141649\u create\u equipes\u table.php
您必须更改此迁移中的一个,以进行第一次称为第二次迁移的第一次迁移
例如

2018_08_31_141536_create_fiches_table.php 
2018_08_30_141649_create_equipes_table.php

您必须首先使
createeEquipestable
然后
CreateFichesTable
这就是我所想的,但没有找到任何信息如何处理这个问题,我正在执行这个命令:php artisan Migration这些迁移的执行顺序是什么?如果您看到迁移文件,它们的开始日期与此类似
2018\u 08\u 10\u 111004\u
,你能显示两个文件名吗???
2018\u 08\u 31\u 141536\u create\u fiches\u table.php
2018\u 09\u 03\u 141649\u create\u equipes\u table.php
所以我想我必须手动更改日期?
2018_08_31_141536_create_fiches_table.php 
2018_08_30_141649_create_equipes_table.php