Bug 37000: (follow-up) Add foreign key last
Certain configurations of MySQL will not allow a column to be changed from nullable to non-nullable if the column has a foreign key constraint. Add the foreign key constraint last to avoid issues from this. Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
This commit is contained in:
parent
8cedcfd5c8
commit
8e788af50b
1 changed files with 12 additions and 3 deletions
|
@ -12,9 +12,8 @@ return {
|
||||||
$dbh->do(
|
$dbh->do(
|
||||||
q{
|
q{
|
||||||
ALTER TABLE bookings
|
ALTER TABLE bookings
|
||||||
ADD COLUMN `pickup_library_id` varchar(10) DEFAULT NULL COMMENT 'Identifier for booking pickup library' AFTER `item_id`,
|
ADD COLUMN `pickup_library_id` varchar(10) DEFAULT NULL COMMENT 'Identifier for booking pickup library' AFTER `item_id`
|
||||||
ADD CONSTRAINT `bookings_ibfk_4` FOREIGN KEY (`pickup_library_id`) REFERENCES `branches` (`branchcode`) ON DELETE CASCADE ON UPDATE CASCADE
|
}
|
||||||
}
|
|
||||||
) == 1
|
) == 1
|
||||||
&& say_success( $out, "Added column 'bookings.pickup_library_id'" );
|
&& say_success( $out, "Added column 'bookings.pickup_library_id'" );
|
||||||
|
|
||||||
|
@ -59,5 +58,15 @@ return {
|
||||||
}
|
}
|
||||||
) == 1 && say_success( $out, "Updated column 'bookings.pickup_library_id' to NOT NULL" );
|
) == 1 && say_success( $out, "Updated column 'bookings.pickup_library_id' to NOT NULL" );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
unless ( foreign_key_exists( 'bookings', 'bookings_ibfk_4' ) ) {
|
||||||
|
$dbh->do(
|
||||||
|
q{
|
||||||
|
ALTER TABLE bookings
|
||||||
|
ADD CONSTRAINT `bookings_ibfk_4` FOREIGN KEY (`pickup_library_id`) REFERENCES `branches` (`branchcode`) ON DELETE CASCADE ON UPDATE CASCADE
|
||||||
|
}
|
||||||
|
) == 1
|
||||||
|
&& say_success( $out, "Added foreign key 'bookings_ibfk_4' to column 'bookings.pickup_library_id'" );
|
||||||
|
}
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue