拉拉维尔。错误: 150 "Foreign key constraint is incorrectly formed"



我有一个用户信息表:

Schema::create('user_information', function (Blueprint $table){
$table->increments('id');
$table->string('full_name');
$table->integer('user_id');
$table->string('nationality');
$table->integer('profession_id');
$table->string('university');
$table->string('academic_degree');
$table->string('company')->nullable();
$table->integer('country_id');
$table->string('phone_number');
$table->text('description')->nullable();
$table->integer('age')->nullable();
$table->string('photo_url')->nullable();
$table->integer('company_id')->nullable();
$table->integer('social_network_id')->nullable();
$table->timestamps();
$table->softDeletes();
});

在其他迁移中,我更新表,特别是外键:

Schema::table('user_information', function (Blueprint $table){
$table->unsignedBigInteger('user_id')->change();
$table->unsignedBigInteger('profession_id')->change();
$table->unsignedBigInteger('country_id')->change();
$table->unsignedBigInteger('company_id')->nullable()->change();
$table->unsignedBigInteger('social_network_id')->nullable()->change();
$table->unsignedBigInteger('register_type_id')->nullable()->change();
$table->foreign('user_id')->references('id')->on('users');
$table->foreign('profession_id')->references('id')->on('profession');
$table->foreign('country_id')->references('id')->on('country');
$table->foreign('company_id')->references('id')->on('company');
$table->foreign('social_network_id')->references('id')->on('social_network');
$table->foreign('register_type_id')->references('id')->on('register_type');
});

然而,当我运行迁移时,我会得到下一个错误代码:

Migrating: 2021_06_03_155507_update_foreign_keys
In Connection.php line 678:
SQLSTATE[HY000]: General error: 1005 Can't create table `civgeo`.`user_information` (errno: 150 "Foreign key constraint is incorrectly formed") (SQL: alter table `user
_information` add constraint `user_information_profession_id_foreign` foreign key (`profession_id`) references `profession` (`id`))

In Connection.php line 471:
SQLSTATE[HY000]: General error: 1005 Can't create table `civgeo`.`user_information` (errno: 150 "Foreign key constraint is incorrectly formed")

所有用作外键的表都已在用户信息表之前创建

好吧,这是我的错误我的错误是,在外国表格中,我将密钥声明为

this->incrementes('id'); 

当我应该宣布它为时

this->id();

相关内容

最新更新