创建迁移时的SQL外键常规错误1215

时间:2015-06-13 17:54:32

标签: php mysql laravel

我构建了两个迁移:

else

和另一个:

public function up()
{
    Schema::create('incidents', function (Blueprint $table) {
        $table->increments('id');
        $table->string('user_id');
        $table->integer('incident_type_id')->unsigned();
        $table->string('type');
        $table->string('incident_reference');
        $table->integer('incident_id');
        $table->date('date');
        $table->time('time');
        $table->string('location');
        $table->string('street');
        $table->string('city');
        $table->double('latitude', 10, 6);
        $table->double('longitude', 10, 6);
        $table->smallInteger('incident_archived')->default(0);
        $table->timestamps();
    });
}

现在我想使用incident_id作为事件表的外键。但我得到错误:无法添加外键约束。首先我认为是导致故障的迁移顺序,因此响应表将在事件表之前创建。但这种情况并非如此。那么为什么我使用incident_id作为外键来阻止呢?

谢谢

0 个答案:

没有答案