The INSERT statement conflicted with the FOREIGN KEY constraint
Question

Hello,


I know that there are plenty of questions regarding this topic, but I just can't get the hang of it and would very much aprreciate it, if someone could help me.


To give you some context: My programm was working just fine, but at some point the tuple of one entity were deleted ( I don't know why). To fix this problem, I decided to create the same, old entity out of an excel sheet and replaced the new entity in my code. The programm is now able to start, but I am not able to safe certain data.


These are my two entities. MitarbeiterNeu was created from the excel sheet and contains information about staff.  The staff has to upload certain data which wil be safed in MitarbeiterVorstellung and should have a 1:1 relationship. 

Id MitarbeiterNeu:


Id MitarbeiterVorstellung:



When I try to upload something I get this error:

The INSERT statement conflicted with the FOREIGN KEY constraint "OSFRK_OSUSR_VHN_MITARBEITERVORSTELLUNG1_OSUSR_VHN_MITARBEITERNEU_ID". The conflict occurred in database "PRHT1U002", table "dbo.OSUSR_VHN_MITARBEITERNEU", column 'ID'. The statement has been terminated. 


I am able to upload a tuple if I set the delete rule to ignore, but the tuple is empty then. It seems that the foreign key of my entity is wrong and it can't connect the upoaded data with an entry of the entity MitarbeiterNeu, like I did before. What am I doing wrong?


PS: Sorry that my entities are written in German, I hope that doesn't irretate. I'll start writing in English after this project :D

Solution

So I was able to solve my problem after severel hours of work. My databse was apparently just working fine. I just committed a wrong variable type at some point.

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.