cascade delete of civicrm_financial_type to civicrm_entity_financial_account
The civicrm_entity_financial_account table stores, amongst other things, the relationships between civicrm_financial_type and civicrm_financial_account records.
- Current situation
When financial types are deleted, there are stranded records in civicrm_entity_financial_account with no referent for their financial_type_id.
- Proposed change
When a financial type with id=n is going to be deleted, first
DELETE FROM civicrm_entity_financial_account WHERE financial_type_id=n;
On upgrade, run something like
DELETE efa.* FROM civicrm_entity_financial_account efa LEFT JOIN civicrm_financial_type ft ON efa.financial_type_id=ft.id WHERE ft.id IS NULL;