We created a database template that gets executed during the installation of a web application (that we also created).
After the application ran in a live scenario for a while, it inherited CONSTRAINTS without our intervention, meaning if we export the database, there are now constraints below some of the table creation blocks.
We want to give this application to someone else, and it requires the database template so they can install it (which we no longer have), and I would like to know if it is safe to remove these constraints (that we did not physically create), and give them a clean template, with only table creations?
Here is an example of one of them, there are roughly 30 tables and now roughly 10 mysterious constraints.
--
-- Table structure for table `blocked_period_rooms`
--
CREATE TABLE IF NOT EXISTS `blocked_period_rooms` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`blocked_period_id` int(11) NOT NULL,
`room_type_id` int(11) NOT NULL,
`quantity` int(11) NOT NULL,
PRIMARY KEY (`id`),
KEY `blocked_period_id` (`blocked_period_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;
--
-- Constraints for table `blocked_period_rooms`
--
ALTER TABLE `blocked_period_rooms`
ADD CONSTRAINT `blocked_period_rooms_ibfk_1` FOREIGN KEY (`blocked_period_id`) REFERENCES `blocked_periods` (`id`) ON DELETE CASCADE ON UPDATE CASCADE;
Here is another example.
ALTER TABLE `guest_ip_addresses`
ADD UNIQUE KEY `guest_id` (`guest_id`,`ipaddress`),
ADD KEY `for_foreignkey_of_guest` (`guest_id`);
ALTER TABLE `guest_ip_addresses`
ADD CONSTRAINT `foreignkey_guest` FOREIGN KEY (`guest_id`) REFERENCES `guests` (`id`) ON DELETE CASCADE ON UPDATE CASCADE;
I'm not a database expert and don't fully understand how/why we're ending up with code in the database like this, any help is VERY appreciated.
CREATE CONSTRAINT
statements when you define tables with relationships.