fix: refs #6371 balanceNestTree add constraint #2039

Merged
robert merged 1 commits from 6371-fixCreateConstraint into dev 2024-02-14 13:48:58 +00:00
1 changed files with 5 additions and 3 deletions

View File

@ -6,9 +6,11 @@ CHANGE COLUMN IF EXISTS `Id_Gasto` `expenseFk` varchar(10) DEFAULT NULL;
ALTER TABLE vn.balanceNestTree ALTER TABLE vn.balanceNestTree
MODIFY COLUMN IF EXISTS expenseFk varchar(10) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci DEFAULT NULL NULL; MODIFY COLUMN IF EXISTS expenseFk varchar(10) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci DEFAULT NULL NULL;
UPDATE vn.balanceNestTree UPDATE vn.balanceNestTree b
SET expenseFk = NULL LEFT JOIN vn.expense e ON e.id = b.expenseFk COLLATE utf8mb3_general_ci
WHERE expenseFk =''; 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 ALTER TABLE IF EXISTS vn.balanceNestTree ADD CONSTRAINT balanceNestTree_expense_FK
FOREIGN KEY (expenseFk) REFERENCES vn.expense(id) ON DELETE CASCADE ON UPDATE CASCADE; FOREIGN KEY (expenseFk) REFERENCES vn.expense(id) ON DELETE CASCADE ON UPDATE CASCADE;