From c97c758bd4191d8d74b0b77d5f9d547f1f93a6b2 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 Signed-off-by: Katrin Fischer (cherry picked from commit 495f0d2caa8f75da5f428b8a18e58ce248a9fea1) Signed-off-by: Fridolin Somers --- 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.39.5