无法添加外键约束-bigIncrements与增量

时间:2019-04-14 17:31:11

标签: php mysql laravel foreign-keys

我创建了迁移文件,由于某种原因,它提供了General error: 1215 Cannot add foreign key constraint。我尝试了各种解决方案,例如将$table->engine = 'InnoDB';添加到表中,重命名迁移文件,以便可以在users之前生成sellers表。他们都没有工作...

这些是迁移表:

用户迁移表

Schema::create('users', function (Blueprint $table) {
        $table->bigIncrements('id');
        $table->string('name');
        $table->string('email')->unique();
        $table->timestamp('email_verified_at')->nullable();
        $table->string('password');
        $table->rememberToken();
        $table->timestamps();
    });

卖家迁移表

 Schema::create('sellers', function (Blueprint $table) {
        $table->bigIncrements('id', true);
        $table->string('name');
        $table->string('surname');
        $table->string('phone');
        $table->unsignedInteger('user_id');
        $table->timestamps();

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

但是,在我将$table->bigIncrements('id')表中的$table->increments('id')更改为users之后,它成功了!那么,当主键为SQLSTATE[HY000]: General error: 1215 Cannot add foreign key constraint时为什么会出现此错误bigIncrements?还是错误的根源完全不同而我误解了?

0 个答案:

没有答案