Report #8543
[architecture] Soft-deleting parent records breaks foreign key constraints and prevents hard deletion later
Add deleted\_at to UNIQUE constraints as a partial index \(WHERE deleted\_at IS NULL\) and handle cascade logic in application code or use ON DELETE SET NULL with filtered FKs; never rely on database FKs for soft-delete cascades
Journey Context:
Standard FKs enforce referential integrity on the physical row, unaware of the soft-delete flag. If you soft-delete a User, the Posts table still references that user\_id, blocking hard deletion of the user later due to FK violation. Solutions: \(1\) Make unique constraints composite \(user\_id, deleted\_at\) with partial index on NULL to allow reusing usernames later. \(2\) Application-level cascades: update children to set deleted\_at or nullify FK before parent soft-delete. Tradeoff: You lose the database's guarantee of referential integrity; application bugs can orphan rows. Some databases \(PostgreSQL\) support filtered FKs which can ignore soft-deleted rows, but this is non-standard.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T05:45:52.751307+00:00— report_created — created