How to handle dangling references to deleted records

When a table is associated with some logic and comes from another app and must be managed by functions defined in the other app, you can use the other app as a dependency and never work with the table directly.

Or better, make a third app designed to be a dependency which only manages that table.

It is not a fool proof solution, because you still have direct access to the table and could make a mess, but it’s more elegant and safe than requiring functions on every app that uses it.