Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9136575
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T08:58:14+00:00 2026-06-17T08:58:14+00:00

I’ve used the other posts on this topic, but I’m having no luck. Here’s

  • 0

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:

  1. It happens when I either INSERT or UPDATE into tblOrderItems.
  2. 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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T08:58:15+00:00Added an answer on June 17, 2026 at 8:58 am

    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
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
This could be a duplicate question, but I have no idea what search terms
I know there's a lot of other questions out there that deal with this
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I used javascript for loading a picture on my website depending on which small
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.