From 2a959668f3d02b5c555722e8eb0d473d497a7243 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Mon, 25 Mar 2024 16:51:01 +0100 Subject: [PATCH] Bug 35610: Set branchcode to NULL before adding the FK Signed-off-by: Victor Grousset/tuxayo --- installer/data/mysql/atomicupdate/bug_35610.pl | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/installer/data/mysql/atomicupdate/bug_35610.pl b/installer/data/mysql/atomicupdate/bug_35610.pl index e9e2c10725..6143bd9e11 100755 --- a/installer/data/mysql/atomicupdate/bug_35610.pl +++ b/installer/data/mysql/atomicupdate/bug_35610.pl @@ -8,6 +8,12 @@ return { my ( $dbh, $out ) = @$args{qw(dbh out)}; unless ( foreign_key_exists('old_reserves', 'old_reserves_ibfk_branchcode') ) { + $dbh->do(q{ + UPDATE old_reserves + SET branchcode = NULL + WHERE branchcode NOT IN (SELECT branchcode FROM branches) + }); + $dbh->do(q{ ALTER TABLE old_reserves ADD CONSTRAINT `old_reserves_ibfk_branchcode` FOREIGN KEY (`branchcode`) REFERENCES `branches` (`branchcode`) ON DELETE SET NULL ON UPDATE CASCADE; -- 2.44.0