Bug 10363: Fix Updatedb entry on MariaDB
authorJonathan Druart <jonathan.druart@bugs.koha-community.org>
Fri, 23 Oct 2015 13:20:17 +0000 (14:20 +0100)
committerTomas Cohen Arazi <tomascohen@theke.io>
Fri, 23 Oct 2015 13:23:42 +0000 (10:23 -0300)
With MariaDB, I get the following error:

ERROR 1832 (HY000): Cannot change column 'av_id': used in a foreign key
constraint 'authorised_values_branches_ibfk_1'

The solution would be to remove the constraints, modify the columns and
finally reintroduce the foreign keys.

Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
installer/data/mysql/updatedatabase.pl

index fd034ab..f5b35a8 100755 (executable)
@@ -11099,9 +11099,16 @@ if ( CheckVersion($DBversion) ) {
 $DBversion = "3.21.00.036";
 if ( CheckVersion($DBversion) ) {
    $dbh->do(q{
-       ALTER TABLE authorised_values_branches
-         CHANGE av_id av_id INT( 11 ) NOT NULL,
-         CHANGE branchcode branchcode VARCHAR( 10 ) NOT NULL
+        ALTER TABLE authorised_values_branches
+        DROP FOREIGN KEY authorised_values_branches_ibfk_1,
+        DROP FOREIGN KEY authorised_values_branches_ibfk_2
+    });
+    $dbh->do(q{
+        ALTER TABLE authorised_values_branches
+        MODIFY av_id INT( 11 ) NOT NULL,
+        MODIFY branchcode VARCHAR( 10 ) NOT NULL,
+        ADD FOREIGN KEY (`av_id`) REFERENCES `authorised_values` (`id`) ON DELETE CASCADE,
+        ADD FOREIGN KEY (`branchcode`) REFERENCES `branches` (`branchcode`) ON DELETE CASCADE
    });
    print "Upgrade to $DBversion done (Bug 10363: There is no package for authorised values)\n";
    SetVersion($DBversion);