diff --git a/html/admin/sql/patch/upgrade97.sql b/html/admin/sql/patch/upgrade97.sql
index 28d268129..f2232ab94 100644
--- a/html/admin/sql/patch/upgrade97.sql
+++ b/html/admin/sql/patch/upgrade97.sql
@@ -792,6 +792,8 @@ update mod_payment set jrn_def_id=3 where mp_type='ACH';
alter table mod_payment drop mp_type;
+delete from mod_payment where jrn_def_id not in (select jrn_def_id from jrn_def);
+
alter table mod_payment add constraint mod_payment_jrn_def_id_fk foreign key (jrn_def_id) references jrn_def(jrn_def_id) on delete cascade on update cascade;
comment on column mod_payment.jrn_def_id is 'Ledger using this payment method';