2

INSERT statement conflicts with the foreign key. I may be entering the foreign key incorrectly.

Error:

No row was updated.

The data in row 1 was not committed.
Error Source: .Net SqlClient Data Provider.
Error Message: The INSERT statement conflicted with the FOREIGN KEY constraint "FK_Movie_Director". The conflict occurred in database table Director column Director ID.

Foreign Key

The Project Tables

ExecuteInsertMovie

ExecuteInsertDirector

ErrorMessage

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
KPIT
  • 27
  • 1
  • 1
  • 5
  • Foreign keys are like references which points to some other column.when you declare a foreign key constraint on a column you must enter the value which is in the column to which its referring.Make sure you are entering the right value – AgentP Mar 24 '19 at 03:19
  • I believe I'm entering the correct value according to the table I was given. – KPIT Mar 24 '19 at 03:24
  • Update the question with the data present in both table and the query that you are trying to execute – AgentP Mar 24 '19 at 03:33
  • Both the queries are fine.Have you entered any data to Director table? Post it and please post the query that giving the Error Message: The INSERT statement conflicted with the FOREIGN KEY constraint "FK_Movie_Director". The conflict occurred in database table Director column Director ID – AgentP Mar 24 '19 at 03:59
  • Posted the error message. No, theirs nothing in my Director Table. It's completely empty. – KPIT Mar 24 '19 at 04:53
  • **PLEASE** post the code **here** (table structure, query etc.), as properly formatted text - **NOT** as links to external resources .... – marc_s Mar 24 '19 at 07:09

2 Answers2

1

Since You don't have any data in director table you can't perform entry to movie table(because of foreign key reference) so first enter some data into the director table then enter data into movie table

For more details you can refer to this link INSERT statement conflicted with the FOREIGN KEY constraint - SQL Server

AgentP
  • 6,261
  • 2
  • 31
  • 52
  • 1
    Wow, thank you! That's actually understandable, I Input some data in the Director table and now I'm able to proceed with the Movie Table. Thanks again. – KPIT Mar 24 '19 at 06:43
0

Can you provide the executed insert query ? make sure that the value you are inserting into a column that references another table exists in that table. i.e in your example table, if you are inserting to a movie table the DirctorID should exist in the Director tale.

amir
  • 31
  • 6