外键

时间:2015-08-31 14:26:52

标签: laravel-5

当我尝试在两个表之间设置关系时,我收到错误:

  
    

D:\ wamp \ www> php artisan migrate迁移表已成功创建。

  
     

[Illuminate \ Database \ QueryException] SQLSTATE [HY000]:常规   错误:1215无法添加外键约束(SQL:alter table   rittenregistratie添加co nstraint   rittenregistratie_karakterritid_foreign外键(karakterritid)   关于d elete cascade的参考karakterritid

     

[PDOException] SQLSTATE [HY000]:常规错误:1215无法添加   外键约束

     

d:\瓦帕\ WWW>

这是我的移民rittenregistratie(它的荷兰语):

    <?php

use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateRittenregistratieTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('rittenregistratie', function (Blueprint $table) 
        {
            $table->increments('id');
            $table->integer('user_id')->unsigned();
            $table->timestamps('datum');
            $table->integer('beginstand');
            $table->integer('eindstand');
            $table->text('van');
            $table->text('naar');
            $table->text('bezoekadres');
            $table->text('geredenroute');
            $table->integer('karakterritid')->default(1);
            $table->text('toelichting');
            $table->integer('kilometerszakelijk');
            $table->integer('kilomteresprive');

            $table->foreign('user_id')
                        ->references('id')
                        ->on('users')
                        ->onDelete('cascade');

            $table->foreign('karakterritid')
                        ->references('id')
                        ->on('karakterrit')
                        ->onDelete('cascade');
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::drop('rittenregistratie');
    }
}

这是我想要涉及的地方:

<?php

use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateKarakterritTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('karakterrit',function(Blueprint $table)
        {
            $table->increments('id');
            $table->text('rit');          
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::drop('karakterrit');
    }
}

我做错了什么?

0 个答案:

没有答案