在创建user
迁移后,我创建了users_contact_lists
,对于此项目的迁移,我会收到此错误:
外键约束格式不正确
我在SO中阅读了一些问题,但找不到任何问题。
Schema::create('users_contact_lists', function (Blueprint $table) {
$table->id();
$table->unsignedBigInteger('user_id')->nullable();
$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
$table->string('mobile_number');
$table->timestamps();
});
而且我无法通过此代码解决此问题:
1) $table->unsignedBigInteger('user_id'); 2) $table->unsignedInteger('user_id'); 3) $table->unsignedInteger('user_id')->nullable();
答案 0 :(得分:0)
问题已解决:
$table->bigIncrements('id');
$table->unsignedBigInteger('user_id');
$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');