
Laravelで自動で作成される外部キー制約の名前が長すぎることが原因
解決するには?
外部キー制約に短い名前をつける
$table->foreign('team_youtube_id', 'tedh_idfk_1')
->references('id')
->on('team_youtubes')
->onDelete('cascade');
これでいうと、「tedh_idfk_1」がそれにあたります。
具体例
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateTeamYoutubeDownloadHistories extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
const TABLE_NAME = "team_youtube_download_histories";
public function up()
{
if (Schema::hasTable(self::TABLE_NAME)) {
return;
}
Schema::create(self::TABLE_NAME, function (Blueprint $table) {
$table->bigIncrements('id');
$table->bigInteger('team_youtube_id')->unsigned();
$table->timestamps();
$table->foreign('team_youtube_id', 'tedh_idfk_1')
->references('id')
->on('team_youtubes')
->onDelete('cascade');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::drop(self::TABLE_NAME);
}
}

