Laravel error: Integrity constraint violation - foreign key constraint fails

preview_player
Показать описание
Addresses the following database error in Laravel applications: "Integrity constraint violation: 1451 Cannot delete or update a parent row: a foreign key constraint fails". Covers when this happens with both One to Many and Many to Many relationships.

=== CHAPTERS ===
00:00 One to Many example
01:56 Fix the error - dissociate book from author being deleted
03:30 Testing the fix
04:30 Another approach - delete connected books
05:35 Another apporach - cascadeOnDelete
07:29 User experience on cascading deletes
09:24 Many to Many example - Eloquent detach
12:25 Deleting authors impacting book-to-user relationships

=== PRODUCTS I USE ===
(paid link)
Рекомендации по теме
Комментарии
Автор

Another option could be with try-catch exception on the destroy method. For example in my case I have categories that belong to many posts. If I attempt to delete a category that has link associated with it, I throw an exception to the user that cannot delete the category.

scuraluis
Автор

love your video, would love to connect with you beyond youtube ?

rufaiibraheem
welcome to shbcf.ru