0

Okay so i have the following many to many relationship in 3 tables:

**MEAL**
mealID

**FoodProduct**
fpID

**meal_food**
mealID
fpID
quantity

The MEAL and FoodProduct tables are already populated so i just need to select a mealID and a fpID and manually set a quantity.

  • What have you tried so far? How have you added records to MEAL and FoodProduct? – Skippy Feb 19 '17 at 10:40
  • are you using ado.net or EF for DB operations – Yashveer Singh Feb 19 '17 at 10:45
  • 1
    What's wrong with a simple insert into? This is very basic sql.... – Zohar Peled Feb 19 '17 at 10:48
  • 1
    insert into meal_food(mealID,fpID,quantity) values (1,1,5) – Yashveer Singh Feb 19 '17 at 10:48
  • The MEAL and FoodProduct do have records already.And yes i am using .NET Windows Forms. Using INSERT INTO meal_aliment (mealID,alimentID,gramage) VALUES ('1','2','0') generates the following error : {"The INSERT statement conflicted with the FOREIGN KEY constraint \"FK__meal_alim__alime__145C0A3F\". The conflict occurred in database \"FoodDBTEST\", table \"dbo.aliment\", column 'alimentID'.\r\nThe statement has been terminated."} –  Feb 19 '17 at 11:21
  • 1
    You can only insert values corresponding to the values you already have in the related tables. That's the point of foreign keys. – Zohar Peled Feb 19 '17 at 13:58
  • So, is this post just another dupe of the many [INSERT statement conflicted with the FOREIGN KEY constraint](http://stackoverflow.com/questions/2965837/insert-statement-conflicted-with-the-foreign-key-constraint) questions? – Ralph Feb 19 '17 at 21:50
  • Indeed it is i solved it thank you all. –  Mar 12 '17 at 17:58

0 Answers0