MySQL Forums
Forum List  »  Newbie

Re: Error - foreign key restraints
Posted by: Pete Rossetti
Date: November 01, 2017 04:43AM

Thank you for taking the time to reply and help a clear novice with this.

The error message may well say exactly the problem is but not sure how to act on it:)

If I insert all the data (successfully) then try and create relationship between the customer and invoice tables I get this error message!


Error: FOREIGN KEY relationship could not be added!
#1452 - Cannot add or update a child row: a foreign key constraint fails (`cust_invoice`.`#sql-68bb_8e`, CONSTRAINT `#sql-68bb_8e_ibfk_1` FOREIGN KEY (`_fkCust_Id`) REFERENCES `Customers` (`_pkCust_Id`))


The SQL statement gives the code below - have changed a couple of fields (domain and Renewal_Date) to allow null


Your SQL query has been executed successfully.

Show Create Table invoice

---------------------------------------------

invoice CREATE TABLE `invoice` (
 `_pkInvoice_Id` varchar(15) NOT NULL,
 `Date_Due` date NOT NULL,
 `Date_Issued` date NOT NULL,
 `Total_Due` varchar(15) NOT NULL,
 `Invoice_Description` text NOT NULL,
 `Renewal_Date` date NOT NULL,
 `Paid` text NOT NULL,
 `_fkCust_Id` varchar(15) NOT NULL,
 `Domain` text NOT NULL,
 PRIMARY KEY (`_pkInvoice_Id`),
 KEY `_fkCust_Id` (`_fkCust_Id`),
 CONSTRAINT `invoice_ibfk_1` FOREIGN KEY (`_fkCust_Id`) REFERENCES `Customers` (`_pkCust_Id`) ON DELETE NO ACTION ON UPDATE NO ACTION
) ENGINE=InnoDB DEFAULT CHARSET=latin1

---------------------------------------------

Thanks again for your help

Options: ReplyQuote


Subject
Written By
Posted
Re: Error - foreign key restraints
November 01, 2017 04:43AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.