Bug 31673: (bug 31086 follow-up) Drop and constraint to allow updating column

It seems that we cannot edit the column while it has a constraint.
If we remove it, update the oclumn, then re-add it, the update succeeds

Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
(cherry picked from commit 0bd87ce064)

Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
This commit is contained in:
Nick Clemens 2022-10-05 10:16:02 +00:00 committed by Lucas Gass
parent 8052280e59
commit 43cd28d4e8

View file

@ -31,11 +31,19 @@ return {
UPDATE reserves SET branchcode = ( SELECT branchcode FROM branches LIMIT 1) WHERE branchcode IS NULL;
});
# Remove FOREIGN KEY CONSTRAINT
$dbh->do(q{
ALTER TABLE reserves DROP FOREIGN KEY reserves_ibfk_4;
});
# Set the NOT NULL configuration
$dbh->do(q{
ALTER TABLE reserves
MODIFY COLUMN `branchcode` varchar(10) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT 'foreign key from the branches table defining which branch the patron wishes to pick this hold up at'
});
# Replace the constraint
$dbh->do(q{
ALTER TABLE reserves ADD CONSTRAINT reserves_ibfk_4 FOREIGN KEY (branchcode) REFERENCES `branches` (`branchcode`) ON DELETE CASCADE ON UPDATE CASCADE;
});
# Print useful stuff here
say $out "Removed NULL option from branchcode for reserves";