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 4036082
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T12:10:45+00:00 2026-05-20T12:10:45+00:00

To learn databasing, I am creating a movie database. To associate multiple directors with

  • 0

To learn databasing, I am creating a movie database.

To associate multiple directors with a movie, I have the following schema:

movie(m_ID, ....)

m_director(dirID, dirName)//dirID is a autoincrement primary key

m_directs(dirID, m_ID) //dirID, m_ID are set as foreign Keys in the mysql  

database(InnoDB engine)

I have a program that connects to the db that needs to add a movie to the database.

I can easily add a new entry to the movie table and the m_director table, but I am having trouble adding a entry in the m_directs table.

INSERT INTO m_director (dirName) VALUES("Jason Reitman");
INSERT INTO m_directs (dirID, m_ID) VALUES(LAST_INSERT_ID(), "tt0467406");

I am using this sql statement to insert a new director and add the association to the movie. I know the primary key of the movie, but I don’t know the dirID, so I use LAST_INSERT_ID() to get the last id of the director just inserted.

The problem I am having is that I get the following error:

MySql.Data.MySqlClient.MySqlException (0x80004005): Cannot add or 
update a child row: a foreign key constraint fails (`siteproducts`.
`m_directs`, CONSTRAINT `m_directs_ibfk_2` FOREIGN KEY (`dirID`) 
REFERENCES `m_directs` (`dirID`) ON DELETE CASCADE ON UPDATE CASCADE)

Any ideas?

  • 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-05-20T12:10:46+00:00Added an answer on May 20, 2026 at 12:10 pm

    Looks like you have foreign key for m_directs.dirID set to same table and column, not to m_director.dirID

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to learn ADO.NET to build applications based on MS Office. I have
I learn to work with the built-in profile provider of .Net, and have the
I'm trying to learn how to use custom events in Flex. I'm following Oliver
I'm trying to learn C. As a C# developer, my IDE is Visual Studio.
As I learn more and more about OOP, and start to implement various design
I am trying to learn the keyboard shortcuts in Visual Studio in order to
I'd like to learn how to program in Assembler. I've done a bit of
Whilst starting to learn lisp, I've come across the term tail-recursive . What does
I'd love to learn Cocoa, it seems like the best systems language for Mac
I just started to learn Ruby and as a .Net developer, I'm wondering if

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.