"when attempting to soft-delete the parent" - are you sure? A soft-delete attempt should not trigger a DB error.
Aug 8, 2023
5
Level 15
Best Practice: Soft-Deleting Parent with Soft-Deleted Child Models
Hi - I've hit the "Integrity constraint violation: 1451 Cannot delete or update a parent row: a foreign key constraint fails" when attempting to soft-delete the parent of the soft-deleted child. I put this issue through Larry AI and the suggested alternatives are:
- Remove the soft-delete property of the child models.
- Remove the model linkage between parent/child and leave the child models intact when soft-deleting the parent model, effectively leaving 'live' models on the database but orphaned.
- Hard delete everything. The model I'm working with has six child tables and the likelihood of the user mistakenly deleting or misunderstanding the impact of the deletion is probably 33%, so having soft-delete protection is important, but not mission-critical. I've put an 'Are you sure?" alert on the button so that there's an opportunity to cancel the action. My question: In your experience, What are the best practices for handling this? Thanks - Rick
Please or to participate in this conversation.