Cannot add or update a child row: a foreign key constraint fails (`hw2`.`order_item`,?

Follow
  • Follow publicly
  • Follow privately
  • Unfollow
I'm trying to do an insert into my order_item table, but I'm getting this error. Can someone help with why this is happening. Thank you. My sql code to create the tables is ...show more
Best Answer
Did you do the insert into table 'orders' first? Because of the foreign key constraint, orders.id must be populated before attempting to populate order_item.order_id
  • Rate
  • Comment
Sign In 

to add your answer

No other answers

Who is following this question?

    %
    BEST ANSWERS
    Member Since:
    Points: Points: Level
    Total Answers:
    Points this week:
    Follow
     
    Unfollow
     
    Block
     
    Unblock