mysql foreign key ERROR 1451 update cascade not happening - mysql

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.

Related

Foreign key constrains fails when inserting in a table where two foreign keys in one table?

I have a table called tbl_vehicles and in this table, there are two foreign keys these are:
ownerID and
agencyID
tbl_agency:
CREATE TABLE `tbl_agency` (
`agencyID` int(11) NOT NULL,
`ag_agencyName` varchar(50) NOT NULL,
`ag_email` varchar(50) NOT NULL,
`ag_username` varchar(50) NOT NULL,
`ag_password` varchar(15) NOT NULL,
`ag_confirmPassword` int(11) NOT NULL,
`ag_phoneNo` int(11) NOT NULL,
`ag_address` varchar(50) NOT NULL,
`ag_photo` varchar(50) NOT NULL,
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
ALTER TABLE `tbl_agency`
ADD PRIMARY KEY (`agencyID`);
ALTER TABLE `tbl_agency`
MODIFY `agencyID` int(11) NOT NULL AUTO_INCREMENT;
tbl_owner:
CREATE TABLE `tbl_owner` (
`ownerID` int(11) NOT NULL,
`ow_ownerName` varchar(20) NOT NULL,
`ow_nationalID` varchar(50) NOT NULL,
`ow_email` varchar(50) NOT NULL,
`ow_username` varchar(50) NOT NULL,
`ow_password` varchar(15) NOT NULL,
`ow_confirmPassword` int(11) NOT NULL,
`ow_phoneNo` int(11) NOT NULL,
`ow_address` varchar(50) NOT NULL,
`ow_photo` varchar(50) NOT NULL,
) ENGINE=InnoDB DEFAULT CHARSET=latin1
ALTER TABLE `tbl_owner`
ADD PRIMARY KEY (`ownerID`);
ALTER TABLE `tbl_owner`
MODIFY `ownerID` int(11) NOT NULL AUTO_INCREMENT;
tbl_vehicles:
CREATE TABLE `tbl_vehicles` (
`vehiclesID` int(11) NOT NULL,
`ve_name` varchar(100) NOT NULL,
`ve_capacity` varchar(100) NOT NULL,
`ve_fuelType` varchar(100) NOT NULL,
`ve_availability` varchar(100) NOT NULL,
`ve_mileage` varchar(100) NOT NULL,
`ve_color` varchar(100) NOT NULL,
`ve_modelName` varchar(100) NOT NULL,
`ve_brandName` varchar(100) NOT NULL,
`ve_price` varchar(50) NOT NULL,
`ve_licenseCode` int(11) NOT NULL,
`ve_noOfPassenger` int(11) NOT NULL,
`ve_photo` varchar(50) NOT NULL,
`agencyID` int(11) NOT NULL,
`ownerID` int(11) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
ALTER TABLE `tbl_vehicles`
ADD PRIMARY KEY (`vehiclesID`),
ADD KEY `agencyID` (`agencyID`),
ADD KEY `ownerID` (`ownerID`);
ALTER TABLE `tbl_vehicles`
MODIFY `vehiclesID` int(11) NOT NULL AUTO_INCREMENT;
--
-- Constraints for table `tbl_vehicles`
--
ALTER TABLE `tbl_vehicles`
ADD CONSTRAINT `fk_tbl_vehicles_tbl_agency` FOREIGN KEY (`agencyID`) REFERENCES `tbl_agency` (`agencyID`) ON DELETE CASCADE ON UPDATE CASCADE;
ALTER TABLE `tbl_vehicles`
ADD CONSTRAINT `fk_tbl_vehicles_tbl_owner` FOREIGN KEY (`ownerID`) REFERENCES `tbl_owner` (`ownerID`) ON DELETE CASCADE ON UPDATE CASCADE;
If a vehicle belongs to an agency then the owner field should be null and If a vehicle belongs to an owner then the agency field should be null.
But it gives me an error.
Which is:
1452 - Cannot add or update a child row: a foreign key constraint fails (db_lamlex_car_rental.tbl_vehicles, CONSTRAINT
tbl_vehicles_ibfk_2 FOREIGN KEY (ownerID) REFERENCES tbl_owner
(ownerID) ON DELETE CASCADE ON UPDATE CASCADE)
How can I solve this?
Please help.

MySQL Foreign Key syntax error

CREATE TABLE DEPARTMENT ( Dname VARCHAR(15) NOT NULL,
Dnumber INT NOT NULL,
Mgr_ssn CHAR(9) NOT NULL,
Mgr_start_Date DATE,
PRIMARY KEY(Dnumber),
UNIQUE(Dname),
FOREIGN KEY(Mgr_ssn) REFERENCES EMPLOYEE (Ssn)
ON DELETE SET DEFAULT ON UPDATE CASCADE);
I am a beginner in MySQL. The command above gives me this:
Cannot add foreign key constraint
I have tried SHOW ENGINE INNODB STATUS;
I checked EMPLOYEE.Ssn's data type.
Please help.
Edit: My EMPLOYEE table
| employee | CREATE TABLE `employee` (
`Fname` varchar(10) DEFAULT NULL,
`Minit` char(1) DEFAULT NULL,
`Lname` varchar(10) DEFAULT NULL,
`Ssn` char(9) NOT NULL,
`Bdate` date DEFAULT NULL,
`Address` varchar(40) DEFAULT NULL,
`Sex` char(1) DEFAULT NULL,
`Salary` int(11) DEFAULT NULL,
`Super_ssn` char(9) DEFAULT NULL,
`Dno` int(11) DEFAULT NULL,
PRIMARY KEY (`Ssn`),
KEY `Super_ssn` (`Super_ssn`),
CONSTRAINT `employee_ibfk_1` FOREIGN KEY (`Super_ssn`) REFERENCES `EMPLOYEE` (`Ssn`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 |
According to the MySQL docs at https://dev.mysql.com/doc/refman/5.7/en/create-table-foreign-keys.html , you can't use SET DEFAULT with INNODB :
SET DEFAULT: This action is recognized by the MySQL parser, but both InnoDB and NDB reject table definitions containing ON DELETE SET DEFAULT or ON UPDATE SET DEFAULT clauses

mySQL - Unable to Insert Values to Table

I am trying to insert a data to my database table using sql queries. I receive this error when updating,
INSERT INTO `permohonan_cuti` (`permohonan_id`, `baki_cuti_permohonan`, `tarikh_mohon`, `tarikh_mula`, `tarikh_akhir`, `sokongan`, `pengganti`, `tujuan`, `kelulusan`, `pelulus`, `staff_id`, `cuti_id`, `katCuti_id`)
VALUES
(1603, 8, '2017-03-29 16:50:24', '2017-04-04', '0000-00-00', 'Dalam Proses', '39', 'HAL PERIBADI', 'Dalam Proses', NULL, 91, 88, 1),
(1604, 19, '2017-03-29 20:28:12', '2017-03-29', '0000-00-00', 'Dalam Proses', '132', 'DEMAM,BATUK,SELSEMA', 'Lulus', '378078', 141, 138, 5)
MySQL said: Documentation
#1452 - Cannot add or update a child row: a foreign key constraint fails (`ktmbcp_staff`.`permohonan_cuti`, CONSTRAINT `permohonan_cuti_ibfk_1` FOREIGN KEY (`staff_id`) REFERENCES `staff` (`staff_id`) ON DELETE CASCADE ON UPDATE CASCADE)
May I know what cause the problem and how to fix it? Are my tables correct?
Below are the tables,
CREATE TABLE `permohonan_cuti` (
`permohonan_id` int(11) NOT NULL,
`baki_cuti_permohonan` float DEFAULT NULL,
`tarikh_mohon` datetime NOT NULL,
`tarikh_mula` date DEFAULT NULL,
`tarikh_akhir` date DEFAULT NULL,
`sokongan` varchar(50) DEFAULT NULL,
`pengganti` varchar(50) DEFAULT NULL,
`tujuan` varchar(100) NOT NULL,
`kelulusan` varchar(50) DEFAULT NULL,
`pelulus` varchar(10) DEFAULT NULL,
`staff_id` int(11) NOT NULL,
`cuti_id` int(11) NOT NULL,
`katCuti_id` int(11) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
ALTER TABLE `permohonan_cuti`
ADD CONSTRAINT `permohonan_cuti_ibfk_1` FOREIGN KEY (`staff_id`) REFERENCES `staff` (`staff_id`),
ADD CONSTRAINT `permohonan_cuti_ibfk_2` FOREIGN KEY (`cuti_id`) REFERENCES `cuti` (`cuti_id`) ON DELETE CASCADE,
ADD CONSTRAINT `permohonan_cuti_ibfk_3` FOREIGN KEY (`katCuti_id`) REFERENCES `kat_cuti` (`katCuti_id`);
ALTER TABLE `permohonan_cuti`
ADD PRIMARY KEY (`permohonan_id`),
ADD KEY `staff_id` (`staff_id`),
ADD KEY `cuti_id` (`cuti_id`),
ADD KEY `katCuti_id` (`katCuti_id`);
CREATE TABLE `staff` (
`staff_id` int(11) NOT NULL,
`staff_no` varchar(8) NOT NULL,
`ic_no` varchar(20) NOT NULL,
`nama` varchar(50) NOT NULL,
`j_id` int(11) DEFAULT NULL,
`tarikh_khidmat` date DEFAULT NULL,
`gred_id` int(11) DEFAULT NULL,
`l_id` varchar(50) DEFAULT NULL,
`email` varchar(50) DEFAULT NULL,
`no_tel` varchar(12) DEFAULT NULL,
`no_hp` varchar(12) DEFAULT NULL,
`alamat` varchar(100) DEFAULT NULL,
`no_akaun` int(15) DEFAULT NULL,
`no_kwsp` varchar(15) DEFAULT NULL,
`password` varchar(10) NOT NULL,
`nama_waris` varchar(50) DEFAULT NULL,
`tel_waris` varchar(12) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
ALTER TABLE `staff`
ADD CONSTRAINT `staff_ibfk_3` FOREIGN KEY (`j_id`) REFERENCES `jabatan` (`j_id`),
ADD CONSTRAINT `staff_ibfk_4` FOREIGN KEY (`gred_id`) REFERENCES `gred_pekerja` (`gred_id`);
ALTER TABLE `staff`
ADD PRIMARY KEY (`staff_id`),
ADD KEY `j_id` (`j_id`),
ADD KEY `gred_id` (`gred_id`);
The message is pretty clear, you are trying to add a staff_id that doesn't exist in the staff table.

SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row on CONSTRAINT `fk_users_has_ratings_businesses1

I'm getting this error when i try to insert new ratings
Error: SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (`yuldi`.`users_ratings`, CONSTRAINT `fk_users_has_ratings_businesses1` FOREIGN KEY (`business_id`) REFERENCES `businesses` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION)
below database table structure with some foreign keys. i'm confused with adding multiple primary and foreign keys. please help me to sort out this issue
CREATE TABLE IF NOT EXISTS `yuldi`.`businesses` (
`id` INT(11) NOT NULL AUTO_INCREMENT,
`state` VARCHAR(100) NOT NULL,
`slug` VARCHAR(250) NOT NULL,
`city` VARCHAR(100) NOT NULL,
`suburb` VARCHAR(100) NOT NULL,
`business_name` VARCHAR(100) NOT NULL,
`business_address` VARCHAR(250) NOT NULL,
`business_postal` VARCHAR(10) NOT NULL,
`business_postal_id` INT(11) NOT NULL,
`business_phone` VARCHAR(50) NOT NULL,
`business_phone1` VARCHAR(50) NOT NULL,
`business_phone2` VARCHAR(50) NOT NULL,
`business_email` VARCHAR(100) NOT NULL,
`business_website` VARCHAR(200) NOT NULL,
`business_details` VARCHAR(5000) NOT NULL,
`business_openinghours` VARCHAR(200) NOT NULL,
`business_service` VARCHAR(200) NOT NULL,
`business_addtionalinfo` VARCHAR(200) NOT NULL,
`business_lat` FLOAT(10,6) NOT NULL,
`business_lng` FLOAT(10,6) NOT NULL,
`identity` VARCHAR(100) NOT NULL,
`status` INT(11) NOT NULL,
PRIMARY KEY (`id`))
ENGINE = InnoDB
AUTO_INCREMENT = 232
DEFAULT CHARACTER SET = utf8;
CREATE TABLE IF NOT EXISTS `yuldi`.`ratings` (
`id` VARCHAR(36) NOT NULL,
`model` VARCHAR(255) NOT NULL,
`value` FLOAT(8,4) NULL DEFAULT '0.0000',
`comment` TEXT NULL DEFAULT NULL,
`created` DATETIME NULL DEFAULT NULL,
`modified` DATETIME NULL DEFAULT NULL,
PRIMARY KEY (`id`),
UNIQUE INDEX `UNIQUE_RATING` (`model` ASC))
ENGINE = InnoDB
DEFAULT CHARACTER SET = utf8;
CREATE TABLE IF NOT EXISTS `yuldi`.`users` (
`id` INT(11) NOT NULL AUTO_INCREMENT,
`user_email` VARCHAR(255) NULL DEFAULT NULL,
`user_password` CHAR(100) NULL DEFAULT NULL,
`user_name` VARCHAR(255) NULL DEFAULT NULL,
`user_code` VARCHAR(255) NULL DEFAULT NULL,
`user_status` TINYINT(4) NULL DEFAULT '0',
`created` DATETIME NULL DEFAULT NULL,
`modified` DATETIME NULL DEFAULT NULL,
`ip_address` VARCHAR(15) NOT NULL,
PRIMARY KEY (`id`))
ENGINE = InnoDB
AUTO_INCREMENT = 14
DEFAULT CHARACTER SET = utf8;
CREATE TABLE IF NOT EXISTS `yuldi`.`users_ratings` (
`user_id` INT(11) NOT NULL,
`rating_id` VARCHAR(36) NOT NULL,
`business_id` INT(11) NOT NULL,
PRIMARY KEY (`user_id`, `rating_id`, `business_id`),
INDEX `fk_users_has_ratings_ratings1_idx` (`rating_id` ASC),
INDEX `fk_users_has_ratings_users1_idx` (`user_id` ASC),
INDEX `fk_users_has_ratings_businesses1_idx` (`business_id` ASC),
CONSTRAINT `fk_users_has_ratings_businesses1`
FOREIGN KEY (`business_id`)
REFERENCES `yuldi`.`businesses` (`id`)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `fk_users_has_ratings_ratings1`
FOREIGN KEY (`rating_id`)
REFERENCES `yuldi`.`ratings` (`id`)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `fk_users_has_ratings_users1`
FOREIGN KEY (`user_id`)
REFERENCES `yuldi`.`users` (`id`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB
DEFAULT CHARACTER SET = utf8;
The problem is coming from this:
CONSTRAINT `fk_users_has_ratings_businesses1`
FOREIGN KEY (`business_id`)
REFERENCES `yuldi`.`businesses` (`id`)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
The record you're trying to insert / update - probably user_ratings - is foreign keyed to the businesses table; you can't create a user_ratings record without a business_id, and that business_id must actually exist as an id in the businesses table.

MySQL Foreign key constraint - Error 1452 - Cannot add or update child row

I've used the other posts on this topic, but I'm having no luck.
Here's the code I execute:
UPDATE tblOrderItems SET `ItemID` = 0004 WHERE `OrderNum`= 203 AND `OrderItemID` = 26
Here's my error:
Error Code: 1452. Cannot add or update a child row: a foreign key constraint fails (`cai0066`.`tblOrderItems`, CONSTRAINT `ItemID` FOREIGN KEY (`ItemID`) REFERENCES `tblCatalogItems` (`ItemID`))
Notes:
It happens when I either INSERT or UPDATE into tblOrderItems.
tblCatalogItems does have an ItemID of 0004. See: this
Here are the create statements generated by MySQL Workbench:
delimiter $$
CREATE TABLE `tblCatalogItems` (
`ItemID` varchar(10) NOT NULL DEFAULT '',
`ItemName` varchar(50) DEFAULT NULL,
`Wholesale` decimal(10,2) DEFAULT NULL,
`Cost5-10` decimal(10,2) DEFAULT NULL,
`Cost11-19` decimal(10,2) DEFAULT NULL,
`Cost20` decimal(10,2) DEFAULT NULL,
`Retail` decimal(10,2) DEFAULT NULL,
PRIMARY KEY (`ItemID`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1$$
delimiter $$
CREATE TABLE `tblItemCosts` (
`Cost` decimal(10,2) DEFAULT NULL,
`VendorID` int(11) NOT NULL,
`ItemID` varchar(10) NOT NULL,
KEY `VendorID_idx` (`VendorID`),
KEY `ItemID_idx` (`ItemID`),
CONSTRAINT `VendorID` FOREIGN KEY (`VendorID`) REFERENCES `tblVendors` (`VendorID`) ON DELETE NO ACTION ON UPDATE NO ACTION
) ENGINE=InnoDB DEFAULT CHARSET=latin1$$
delimiter $$
CREATE TABLE `tblOrderItems` (
`OrderItemID` int(11) NOT NULL AUTO_INCREMENT,
`OrderNum` int(11) NOT NULL,
`PayPalTxnID` int(10) DEFAULT NULL,
`Description` varchar(225) DEFAULT NULL,
`Quantity` int(11) DEFAULT NULL,
`UnitPrice` decimal(10,2) DEFAULT NULL,
`ItemStatus` varchar(30) DEFAULT NULL,
`TrackingNumber` varchar(50) DEFAULT NULL,
`ShippingCost` decimal(10,2) DEFAULT NULL,
`ItemID` varchar(50) DEFAULT NULL,
`TotalPrice` decimal(10,2) DEFAULT NULL,
PRIMARY KEY (`OrderItemID`,`OrderNum`),
UNIQUE KEY `PayPalTxnID_UNIQUE` (`PayPalTxnID`),
KEY `PayPalTxnID_idx` (`PayPalTxnID`),
KEY `UnitPrice_idx` (`ItemID`),
KEY `OrderNum_idx` (`OrderNum`),
CONSTRAINT `ItemID` FOREIGN KEY (`ItemID`) REFERENCES `tblCatalogItems` (`ItemID`),
CONSTRAINT `OrderNum` FOREIGN KEY (`OrderNum`) REFERENCES `tblOrders` (`OrderNum`) ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT `UnitPrice` FOREIGN KEY (`ItemID`) REFERENCES `tblCatalogItems` (`ItemID`) ON DELETE NO ACTION ON UPDATE NO ACTION
) ENGINE=InnoDB AUTO_INCREMENT=7678 DEFAULT CHARSET=latin1$$
delimiter $$
CREATE TABLE `tblOrderItemStatus` (
`OrderItemID` int(11) NOT NULL,
`OrderDate` varchar(12) DEFAULT NULL,
`DesignProofSent` varchar(12) DEFAULT NULL,
`SubmittedToProduction` varchar(12) DEFAULT NULL,
`InProduction` varchar(12) DEFAULT NULL,
`Shipped` varchar(12) DEFAULT NULL,
PRIMARY KEY (`OrderItemID`),
UNIQUE KEY `OrderItemID_UNIQUE` (`OrderItemID`),
KEY `OrderItemID_idx` (`OrderItemID`),
CONSTRAINT `OrderItemID` FOREIGN KEY (`OrderItemID`) REFERENCES `tblOrderItems` (`OrderItemID`) ON DELETE NO ACTION ON UPDATE NO ACTION
) ENGINE=InnoDB DEFAULT CHARSET=latin1$$
delimiter $$
CREATE TABLE `tblOrders` (
`OrderNum` int(11) NOT NULL AUTO_INCREMENT,
`PayPalTxnID` int(10) DEFAULT NULL,
`OrderDate` varchar(50) DEFAULT NULL,
`OrderStatus` varchar(10) DEFAULT 'New',
`RushFlag` bit(1) DEFAULT b'0',
`ShipName` varchar(50) DEFAULT NULL,
`ShipEmail` varchar(100) DEFAULT NULL,
`ShipAddress1` varchar(50) DEFAULT NULL,
`ShipAddress2` varchar(50) DEFAULT NULL,
`ShipCity` varchar(50) DEFAULT NULL,
`ShipState` char(2) DEFAULT NULL,
`ShipZip` varchar(10) DEFAULT NULL,
`ShippingCharge` decimal(10,2) DEFAULT NULL,
`TotalCost` decimal(10,2) DEFAULT NULL,
PRIMARY KEY (`OrderNum`),
UNIQUE KEY `PayPalTxnID_UNIQUE` (`PayPalTxnID`)
) ENGINE=InnoDB AUTO_INCREMENT=346 DEFAULT CHARSET=latin1$$
delimiter $$
CREATE TABLE `tblVendors` (
`VendorID` int(11) NOT NULL,
`VendorName` varchar(50) DEFAULT NULL,
PRIMARY KEY (`VendorID`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1$$
I tried the suggestion in this relevant post, but there were no results. This is a new database that hasn't actually been used yet; I've just filled it with fake data. Any ideas would be greatly appreciated.
There is a foreign key constraint on tblOrderItems that its ItemID needs to reference an ItemID that already exists in tblCatalogItems.
CONSTRAINT `ItemID` FOREIGN KEY (`ItemID`) REFERENCES `tblCatalogItems` (`ItemID`),
The message only means that you're trying to update tblOrderItems to reference the item in tblCatalogItems with ItemID= 0004, but that item does not exist.
Since ItemID is a varchar, you probably want to quote the 0004 or it may be converted to an int 4 before conversion to varchar. That may be your problem if the row with ItemID = 0004 actually exists.
UPDATE tblOrderItems SET `ItemID` = '0004' WHERE `OrderNum`= 203 AND `OrderItemID` = 26
Without seeing the table data I can't be sure, but I'm guessing it's because there is no record in tblCatalogItems with an ItemID of '0004'.
Also, you probably need to quote the 0004 in your update statement since the column is defined as character (varchar(10)) not number (int).
There is a foreign key relationship defined between tblCatalogItems.ItemId and tblOrderItems.ItemId which means that any row in tblOrderItems can only have a value for ItemId that matches an ItemId found in tblCatalogItems.
You would therefore need to insert a record into 'tblCatalogItems' with an ItemId of '0004' first, before running your update on tblOrderItems
Alternatively you need to change the SET ItemID = clause in your update to set a value that matches to an ItemId value that actually exists in the tblCatalogItems table
The data type needs to match on both sides of your foreign key constraint. Here you have a varchar(50) referring a varchar(10), which isn't allowed.
CREATE TABLE `tblCatalogItems` (
`ItemID` varchar(10) NOT NULL DEFAULT '',
...
) ENGINE=InnoDB DEFAULT CHARSET=latin1$$
...
CREATE TABLE `tblOrderItems` (
`ItemID` varchar(50) DEFAULT NULL,
...
CONSTRAINT `UnitPrice` FOREIGN KEY (`ItemID`) REFERENCES `tblCatalogItems` (`ItemID`) ON DELETE NO ACTION ON UPDATE NO ACTION
) ENGINE=InnoDB AUTO_INCREMENT=7678 DEFAULT CHARSET=latin1$$