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)")
Sign in to participate in this thread!