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');
}
公司迁移已在执行上述迁移之前完成
当我尝试与外键一起创建表时,出现上述错误。我做错什么了吗?
答案 0 :(得分:1)
请确保在迁移companies
之前先迁移company_eligibilities
,然后将外键ID更改为
无符号大整数,Laravel 5.8将默认外键设置为无符号大整数,对于 6.x 和 7.x :
$table->bigInteger('company_id')->unsigned();
或者,
$table->unsignedBigInteger('company_id');