Back

new migration to add a foreign key


John Michael Biddulph posted 1 week ago

so I have created a new migration to add a reference to the ID field in the PUBS table

public function up() { Schema::table('questions', function (Blueprint $table) { $table->integer('pub_id')->unsigned(); $table->foreign('pub_id')->references('id')->on('pubs')->onDelete('cascade'); }); }

I am getting the error: Exception trace:

1 PDOException::("SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (rtapp.#sql-2dc_13d, CONSTRAINT questions_pub_id_foreign FOREIGN KEY (pub_id) REFERENCES pubs (id) ON DELETE CASCADE)")

John Michael Biddulph replied 1 week ago

I've managed to do it manually now


Sign in to participate in this thread!



We'd like to thank these amazing companies for supporting us