0
我想在laravel中創建表'隊'和'比賽',但是當我運行遷移命令時,出現以下錯誤:errno:150「外鍵約束錯誤地形成「Laravel - 外鍵約束錯誤地形成
Schema::create('competitions', function (Blueprint $table) {
$table->increments('id');
$table->string('name')->unique();
$table->string('team_name');
$table->foreign('team_name')->references('name')->on('teams')->onDelete('cascade');
$table->timestamps();
});
Schema::create('teams', function (Blueprint $table) {
$table->increments('id');
$table->string('name')->unique();
$table->string('place');
$table->string('competition')->nullable();;
$table->foreign('competition')->references('name')->on('competitions')->onDelete('set null');
$table->timestamps();
});
nope沒有工作,仍然是錯誤 – jordibenck