Results 1 to 6 of 6
  1. #1
    Join Date
    Jun 2008
    Posts
    4

    Unanswered: 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?

  2. #2
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    are you sure you are using MySQL?
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  3. #3
    Join Date
    Oct 2007
    Posts
    55
    Provided Answers: 3
    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

  4. #4
    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

  5. #5
    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.

  6. #6
    Join Date
    Jun 2008
    Posts
    4
    ye i fixed it i concatenated the foreign key
    Last edited by matthew15; 06-21-08 at 00:21.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •