If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > Getting a parent key error

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 06-19-08, 19:01
matthew15 matthew15 is offline
Registered User
 
Join Date: Jun 2008
Posts: 4
Getting a parent key error

i get a error message like this: Table RENTAL_ITEM in RENTALB23 does not have a matching parent key.

this is the sql:
CREATE TABLE RENTALB23/RENTAL_ITEM (RENTALITEM# INT PRIMARY KEY,
RENTALTYPE CHAR(3), TITLE CHAR(30), CATEGORY CHAR(15), DUEDATE DATE,
FOREIGN KEY(RENTALTYPE) REFERENCES
RENTALB23/RENTAL_CHARGE(RENTALTYPE), FOREIGN KEY(CATEGORY)
REFERENCES RENTALB23/RENTAL_CHARGE(CATEGORY))

this is the sql for the rental_charge table:
CREATE TABLE RENTALB23/RENTAL_CHARGE (RENTALTYPE CHAR(3),
CATEGORY CHAR(15), CHARGE DECIMAL(5,2), PRIMARY KEY(RENTALTYPE,
CATEGORY))

any ideas what can cause this?
Reply With Quote
  #2 (permalink)  
Old 06-19-08, 22:41
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,525
are you sure you are using MySQL?
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #3 (permalink)  
Old 06-20-08, 14:42
DNance DNance is offline
Registered User
 
Join Date: Oct 2007
Posts: 4
if this is throwing you for a loop, then you need to investigate learning opportunities in your area. The issue is that the value you are trying to insert for either RENTALTYPE or CATEGORY in the table RENTAL_ITEM does not exist in the table RENTAL_CHARGE. If you look at your DDL there is a foreign key defined on those 2 columns, which means you have to have those items in the parent table before you can put them in the child table.
Dave
Reply With Quote
  #4 (permalink)  
Old 06-20-08, 17:31
matthew15 matthew15 is offline
Registered User
 
Join Date: Jun 2008
Posts: 4
well the parent table is: rental_charge

i made that first and then made the RENTAL_ITEM table that has the foreign keys but the error is the same
Reply With Quote
  #5 (permalink)  
Old 06-20-08, 22:08
buckeye234 buckeye234 is offline
Registered User
 
Join Date: Sep 2002
Location: Ohio
Posts: 204
What is the primary key on rental_charge?

What is the foreign key on rental_item?

Look at the error message.

Do the primary key and foreign key match?

Why do you think you get the error?

If you think about it and answer these questions, you will have gotten your answer and learned something.
Reply With Quote
  #6 (permalink)  
Old 06-20-08, 23:16
matthew15 matthew15 is offline
Registered User
 
Join Date: Jun 2008
Posts: 4
ye i fixed it i concatenated the foreign key

Last edited by matthew15; 06-20-08 at 23:21.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On