CHB
CHB

Reputation: 1

mysql foreign key ERROR 1451 update cascade not happening

I am trying to update a field that is referenced as a foreign key in another table.

mysql> update Maintenance set contract='95096916-OLD' where contract='95096916';

ERROR 1451 (23000): Cannot delete or update a parent row: a foreign key constraint fails (systems_doc.Equipment, CONSTRAINT Equipment_ibfk_1 FOREIGN KEY (contract) REFERENCES Maintenance (contract) ON UPDATE CASCADE)

| Maintenance | CREATE TABLE `Maintenance` (
  `contract` char(30) NOT NULL,
  `quote` char(30) NOT NULL,
  `vendor` char(20) NOT NULL,
  `provider` char(20) NOT NULL,
  `product` char(30) NOT NULL,
  `expiryDate` date NOT NULL,
  `annualCost` int(11) NOT NULL,
  `reference` char(13) NOT NULL,
  `purchaseOrder` char(13) NOT NULL,
  `cq` char(10) NOT NULL,
  `cqRenewal` char(10) NOT NULL,
  `comments` char(40) NOT NULL,
  UNIQUE KEY `contract` (`contract`,`expiryDate`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 | 

| Equipment | CREATE TABLE `Equipment` (
  `vendor` char(20) NOT NULL,
  `model` char(30) NOT NULL,
  `serialNumber` char(20) NOT NULL,
  `purchaseOrder` char(20) NOT NULL,
  `purchaseDate` date NOT NULL,
  `contract` char(15) NOT NULL,
  `annualCost` int(11) NOT NULL,
  `comments1` varchar(256) DEFAULT NULL,
  `comments2` varchar(256) NOT NULL,
  PRIMARY KEY (`serialNumber`),
  KEY `contract` (`contract`),
  CONSTRAINT `Equipment_ibfk_1` FOREIGN KEY (`contract`) REFERENCES `Maintenance` (`contract`) ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=latin1 | 

Why isn't it cascading the UPDATE? I don't think it's circular. Thanks for your help. I've read other similar problems, but either I am misinterpreting how it should work, or I've got something setup wrong.

Upvotes: 0

Views: 310

Answers (0)

Related Questions