From 88f508a424e9c7d39217f6fbe9b502e14c173a9c Mon Sep 17 00:00:00 2001 From: robert Date: Wed, 14 Feb 2024 14:42:04 +0100 Subject: [PATCH] fix: refs #6371 balanceNestTree add constraint --- db/versions/10835-brownCarnation/28-balance_nest_tree.sql | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/db/versions/10835-brownCarnation/28-balance_nest_tree.sql b/db/versions/10835-brownCarnation/28-balance_nest_tree.sql index 043bde2e4..6a3fd1edd 100644 --- a/db/versions/10835-brownCarnation/28-balance_nest_tree.sql +++ b/db/versions/10835-brownCarnation/28-balance_nest_tree.sql @@ -6,9 +6,11 @@ CHANGE COLUMN IF EXISTS `Id_Gasto` `expenseFk` varchar(10) DEFAULT NULL; ALTER TABLE vn.balanceNestTree MODIFY COLUMN IF EXISTS expenseFk varchar(10) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci DEFAULT NULL NULL; -UPDATE vn.balanceNestTree - SET expenseFk = NULL - WHERE expenseFk =''; +UPDATE vn.balanceNestTree b + LEFT JOIN vn.expense e ON e.id = b.expenseFk COLLATE utf8mb3_general_ci + SET b.expenseFk = NULL + WHERE b.expenseFk ='' + OR (e.id IS NULL AND b.expenseFk IS NOT NULL); ALTER TABLE IF EXISTS vn.balanceNestTree ADD CONSTRAINT balanceNestTree_expense_FK FOREIGN KEY (expenseFk) REFERENCES vn.expense(id) ON DELETE CASCADE ON UPDATE CASCADE; -- 2.40.1