I have three tables as seen below.
what my requirement is, when I delete a row from a donate_club table, I need to delete all the entries related to this row from 'donationRequest' and 'committments'. Here 'commitments' table has a foreign key relation ship with 'donatinRequest' table. So when I delete an entry from 'donationRequest' table the corresponding entries are being deleted from 'committments' table also. That works fine. Also 'donationRequest' table has a foreign key relationship to 'donate_club' table, so when I delete an entry from 'donate_club' it also deletes related entries from 'donationRequest' table. It is also working fine. Now my requirement is when I delete an entry from 'donate_club', I need to delete all the related entries from both 'doantionRequest' and 'commitments' table.
Now the situation is, when I delete a row from 'donate_club', it automatically deletes related entries from 'donationRequest' table but it doesnt delete anything from 'committments' table eventhough 'committments' table has an entry related to the deleted row from 'donationRequest' table
EDIT: donate_club table create query
CREATE TABLE `donate_club` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`firstName` varchar(100) DEFAULT NULL,
`secondName` varchar(100) DEFAULT NULL,
`email` varchar(100) DEFAULT NULL,
`password` varchar(20) DEFAULT NULL,
`mobile` varchar(20) DEFAULT NULL,
`bloodGroup` varchar(10) DEFAULT NULL,
`age` varchar(10) DEFAULT NULL,
`gender` varchar(20) DEFAULT NULL,
`country` varchar(50) DEFAULT NULL,
`location` varchar(50) DEFAULT NULL,
`latitude` varchar(50) DEFAULT NULL,
`longitude` varchar(50) DEFAULT NULL,
`profilePicFIleName` varchar(100) DEFAULT NULL,
`profilePicURL` text,
PRIMARY KEY (`id`),
UNIQUE KEY `mobile` (`mobile`),
UNIQUE KEY `email` (`email`)
) ENGINE=InnoDB AUTO_INCREMENT=68 DEFAULT CHARSET=utf8
donationRequest create query
CREATE TABLE `donationrequest` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`latitude` varchar(50) DEFAULT NULL,
`longitude` varchar(50) DEFAULT NULL,
`mobile` varchar(15) DEFAULT NULL,
`contactPerson` varchar(50) DEFAULT NULL,
`bloodGroup` varchar(10) DEFAULT NULL,
`bloodBank` varchar(200) DEFAULT NULL,
`location` varchar(100) DEFAULT NULL,
`postedDate` varchar(30) DEFAULT NULL,
`userID` int(11) DEFAULT NULL,
`fcmToken` varchar(1000) DEFAULT NULL,
`requiredDate` varchar(20) DEFAULT NULL,
`need` varchar(20) DEFAULT NULL,
`unit` varchar(5) DEFAULT NULL,
`patient` varchar(50) DEFAULT NULL,
`status` tinyint(4) DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `userID` (`userID`),
CONSTRAINT `fk_to_donate_club_id` FOREIGN KEY (`userID`) REFERENCES `donate_club` (`id`)
ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=332 DEFAULT CHARSET=utf8
committments create table query
CREATE TABLE `commitments` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`userID` varchar(50) DEFAULT NULL,
`fcmTockenPatient` varchar(10000) DEFAULT NULL,
`fcmTockenDonor` varchar(10000) DEFAULT NULL,
`committedDate` varchar(15) DEFAULT NULL,
`patientName` varchar(100) DEFAULT NULL,
`byStanderName` varchar(100) DEFAULT NULL,
`byStanderMobile` varchar(15) DEFAULT NULL,
`bloodGroup` varchar(5) DEFAULT NULL,
`location` varchar(100) DEFAULT NULL,
`hospital` varchar(100) DEFAULT NULL,
`requestID` int(11) DEFAULT NULL,
`isFinished` tinyint(2) DEFAULT NULL,
`receiverID` varchar(50) DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `requestID` (`requestID`),
CONSTRAINT `fk_to_donation_request` FOREIGN KEY (`requestID`) REFERENCES `donationrequest` (`id`)
ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=286 DEFAULT CHARSET=utf8
ON DELETE CASCADE
) should work. Are you claiming that you delete rows from tabledonate_club
and you are left with rows incommitments
that violate the FK constraint? If that happens, it's a bug. Which version are you using? Also: are there anyDELETE
triggers, in any of the tables?