【发布时间】:2019-07-27 05:35:03
【问题描述】:
我正在尝试执行此迁移:
用户:
Schema::create('comments', function (Blueprint $table) {
$table->bigIncrements('id');
$table->string('first_name');
$table->string('last_name');
$table->string('email')->unique();
$table->string('avatar_url');
$table->string('email_verified_at')->nullable();
$table->string('password')->unique();
$table->rememberToken();
$table->timestamps();
$table->softDeletes();
});
文章:
Schema::create('articles', function (Blueprint $table) {
$table->bigIncrements('id');
$table->text('title');
$table->longText('body');
$table->enum('state', ['draft', 'published']);
$table->bigInteger('user_id')->unsigned();
$table->timestamps();
$table->softDeletes();
$table->foreign('user_id')
->references('id')->on('users')
->onUpdate('cascade')->onDelete('cascade');
});
但是当我迁移时出现以下错误:
SQLSTATE[HY000]: 一般错误: 1005 Can't create table
blog_api.#sql-2b70_7b(Errcode: 150 "Foreign key constraint is inc
正确形成”)(SQL:更改表articles添加约束articles_user_id_foreign外键(user_id)引用users<br>(id)在更新级联上删除级联)
我已经尝试将大整数和大增量重命名为简单整数和增量,但没有成功。
【问题讨论】:
-
你是如何定义你的
users.id的? -
您已共享
comments表请共享users表并确保FK和id数据类型匹配!