Postingan lainnya
struktur pivot table antara PERTANYAAN dengan TAG
1 pertanyaan bisa lebih 1 tag, begitu juga sebaliknya
struktur pivot table saya kek gini
Schema::create('question_tag', function (Blueprint $table) {
$table->integer('id_question')->unsigned()->index();
$table->integer('id_tag')->unsigned()->index();
$table->timestamps();
// set primary
$table->primary(['id_question', 'id_tag']);
//set foreign
$table->foreign('id_question')
->references('id')
->on('questions')
->onDelete('cascade')
->onUpdate('cascade');
$table->foreign('id_tag')
->references('id')
->on('tags')
->onDelete('cascade')
->onUpdate('cascade');
});
tapi pas saya insert / update ada error SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (`forum`.`question_tag`, CONSTRAINT `question_tag_id_tag_foreign` FOREIGN KEY (`id_tag`) REFERENCES `tags` (`id`) ON DELETE CASCADE ON UPDATE CASCADE) (SQL: insert into `question_tag` (`id_question`, `id_tag`) values (1, 0), (1, 1), (1, 4), (1, 6))
keknya erornya di struktur pivot tablenya deh, apa saya harus ganti cascadenya..?
0
Belum ada Jawaban. Jadi yang pertama Jawaban
Login untuk ikut Jawaban