Report #4324
[architecture] Foreign key constraints prevent hard-deletion of parent records when children are soft-deleted
Use DEFERRABLE INITIALLY DEFERRED constraints to check FK integrity at transaction commit \(allowing you to hard-delete children first within the transaction\), or implement cascading soft-delete logic in application code that hard-deletes children before parents.
Journey Context:
When using soft-delete \(paranoid pattern\), child records remain in the database with deleted\_at timestamps. Standard ON DELETE CASCADE only triggers on hard DELETE operations. If you attempt to hard-delete a parent after its children are soft-deleted, the FK constraint still sees the children \(soft-deleted doesn't mean gone\) and blocks the operation. The architectural options are: 1\) Deferred constraints \(PostgreSQL feature\) that delay FK checking until COMMIT, allowing you to DELETE FROM children WHERE parent\_id=X; DELETE FROM parent WHERE id=X; in the same transaction. 2\) Application-level cascade that explicitly hard-deletes soft-deleted children first. 3\) Removing FK constraints entirely \(dangerous\). The deferred constraint approach is cleanest but database-specific.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-15T19:14:01.801671+00:00— report_created — created