Illuminate \ Database \ QueryException (23000)
SQLSTATE[23000]: Integrity constraint violation: 1451 Cannot delete or update a parent row: a foreign key constraint fails (project-management
.projects
, CONSTRAINT projects_company_id_foreign
FOREIGN KEY (company_id
) REFERENCES companies
(id
)) (SQL: delete from companies
where id
= 2)
0
votes
1 Answers
0
votes
You can't delete the record that have child relation ships.
In companies table record #2 is used as projects_company_id of projects table.
So, First delete the projects with company_id #2 and delete company with id #2.
Or
you can use ON DELETE CASCADE option for that constraint(like auto delete, Child records will automatically deletes when parent record deleted).