let's say I have these two tables:
CREATE TABLE `tblsuppliers` (
`supplierID` int(11) NOT NULL AUTO_INCREMENT,
`supplierName` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
`phoneNumber` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`emailAddress` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`physicalAddress` varchar(100) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
PRIMARY KEY (`supplierID`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
CREATE TABLE `tblorders` (
`orderID` varchar(100) COLLATE utf8mb4_unicode_ci NOT NULL,
`supplierID` int(11) NOT NULL,
`productID` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
`dateOrdered` date DEFAULT NULL,
`dateArriving` date DEFAULT NULL,
`isJob` bit(1) NOT NULL,
`username` varchar(50) COLLATE utf8mb4_unicode_ci NOT NULL,
`quantity` decimal(10,0) NOT NULL,
`hasArrived` bit(1) DEFAULT NULL,
PRIMARY KEY (`orderID`),
KEY `tblorders_FK_1` (`username`),
KEY `tblorders_FK_2` (`productID`),
KEY `tblorders_FK` (`supplierID`),
CONSTRAINT `tblorders_FK` FOREIGN KEY (`supplierID`) REFERENCES `tblsuppliers` (`supplierID`) ON UPDATE CASCADE,
CONSTRAINT `tblorders_FK_1` FOREIGN KEY (`username`) REFERENCES `tblusers` (`username`) ON UPDATE CASCADE,
CONSTRAINT `tblorders_FK_2` FOREIGN KEY (`productID`) REFERENCES `tblproducts` (`productID`) ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
I want to be able to delete a Supplier but keep their records in Orders, as of now, i'm not able to, I get that exception. I've been looking for a solution here for the last couple of days but as of yet, i've only found that the constraints were the other way around
I'm pretty sure i'm missing a fundamental concept and I'm aware that this type of question has been asked a lot of times here, but from the explanations, I know i'm doing something wrong, just dont know what. I'd appreciate it if I got an explanation of what it was. Thank you