Search code examples
sqlasp.netforeign-key-relationship

The INSERT statement conflicted with the FOREIGN KEY constraint (Parent record exists already)


I'm getting the error "The INSERT statement conflicted with the FOREIGN KEY constraint...." I have searched for similar problems but I cannot find the one that solves mine. Solution I've seen is that I dont have a record on the referenced table. (I have) but still does not work.

I have table called Parent and ParentFeedback which is referencing the Parent table.

I have already created 2 records in Parent. Now when I try to insert a ParentFeedback record using my Insert statement

Insert into ParentFeedback 
Values(@parentid, @feed, @date , @status)

I get an error (shown in the title).

I have made sure already that the parentid that I'm putting exists and I am able to grab it and put it in @parentid.

But why am I still getting that error?

If you want to see it, Click here to be directed to the page.

just search for asdasd firstname and asdasd lastname then put a feedback and submit. asdasd is an existing record in Parent table with ID of 1. which I put for the parentid in my insert.


Solution

  • Hi Guys im really sorry to bother you, I thought that I was passing my parent ID properly but it turns out it aint giving me an ID and its always 0.