Choose a PostgreSQL foreign-key deletion policy without losing the wrong rows
Compare RESTRICT, CASCADE and SET NULL using a small isolated example, then check the actual constraint and dependent rows before changing real data.
PostgreSQL / SQL / Foreign keys / Transactions