Open cruciux opened 8 years ago
I have the need to create a many-to-many on the same table (objects can be associated with a number of other objects).
The migration created tries to use the same foreign key:
public function up() { Schema::create('munition_munition', function (Blueprint $table) { $table->integer('munition_id')->unsigned()->index(); $table->foreign('munition_id')->references('id')->on('munitions')->onDelete('cascade'); $table->integer('munition_id')->unsigned()->index(); $table->foreign('munition_id')->references('id')->on('munitions')->onDelete('cascade'); $table->primary(['munition_id', 'munition_id']); }); }
It should instead do something such as:
public function up() { Schema::create('munition_munition', function (Blueprint $table) { $table->integer('munition_a_id')->unsigned()->index(); $table->foreign('munition_a_id')->references('id')->on('munitions')->onDelete('cascade'); $table->integer('munition_b_id')->unsigned()->index(); $table->foreign('munition_b_id')->references('id')->on('munitions')->onDelete('cascade'); $table->primary(['munition_a_id', 'munition_b_id']); }); }
I have the need to create a many-to-many on the same table (objects can be associated with a number of other objects).
The migration created tries to use the same foreign key:
It should instead do something such as: