SQLSTATE[HY000]: General error: 1005 Can't create table `Data`.`company_eligibilities` (errno: 150 "Foreign key constraint is incorrectly formed")
SQLSTATE[HY000]: General error: 1005 Can't create table `Data`.`company_eligibilities` (errno: 150 "Foreign key constraint is incorrectly formed")
public function up()
{
Schema::create('company_eligibilities', function (Blueprint $table) {
$table->id();
$table->string('marks');
$table->integer('company_id')->unsigned();
$table->timestamps();
$table->foreign('company_id')
->references('id')->on('companies')
->onDelete('cascade')
->onUpdate('cascade');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('company_eligibilities');
}
执行上述迁移之前公司迁移已经完成
当我尝试创建 table 和外键时出现上述错误。我是不是做错了什么??
确保在迁移 companies
之前迁移 companies
,将外键 ID 更改为
unsigned big integer, Laravel 5.8 将默认外键设置为unsigned big integer, 6.x and ]7.x :
$table->bigInteger('company_id')->unsigned();
或者,
$table->unsignedBigInteger('company_id');
public function up()
{
Schema::create('company_eligibilities', function (Blueprint $table) {
$table->id();
$table->string('marks');
$table->integer('company_id')->unsigned();
$table->timestamps();
$table->foreign('company_id')
->references('id')->on('companies')
->onDelete('cascade')
->onUpdate('cascade');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('company_eligibilities');
}
执行上述迁移之前公司迁移已经完成
当我尝试创建 table 和外键时出现上述错误。我是不是做错了什么??
确保在迁移 companies
之前迁移 companies
,将外键 ID 更改为
unsigned big integer, Laravel 5.8 将默认外键设置为unsigned big integer, 6.x and ]7.x :
$table->bigInteger('company_id')->unsigned();
或者,
$table->unsignedBigInteger('company_id');