Answer the question
In order to leave comments, you need to log in
How to make a connection "on demand"?
Good afternoon
There is a link in the table to itself (linked_record_id refers to record_id)
However, it may not always be. For those who do not have a connection, I want to set linked_record_id = 0
However, I fall with an error -
Foreign key violation: 7 ERROR: insert or update on table "records" violates foreign key constraint "records_linked_record_id_foreign"
DETAIL: Key (linked_record_id)=(0) is not present in table "records". (SQL: insert into "records" ("linked_record_id", "company_id", "form_id", "uuid", "updated_at", "created_at") values (0, 1, 1, c4cf5827-447f-355f-bee9-57c3a7fc84f7, 2017-08-21 14:57:46, 2017-08-21 14:57:46) returning "record_id")
Answer the question
In order to leave comments, you need to log in
$table->...->onDelete('set null');
$table->integer('foreign_id')->unsigned()->nullable();
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question