mardi 24 mars 2015

The INSERT statement conflicted with the FOREIGN KEY constraint. The conflict occurred in database


Vote count:

0




I have been having this problem for a couple of hours now. in my sql server, I inserted this query :



INSERT INTO USERS_AVATAR(userId, avatId) VALUES ('1', '213');
INSERT INTO USERS_AVATAR(userId, avatId) VALUES ('2', '312');


but the message shows up saying :



Msg 547, Level 16, State 0, Line 1
The INSERT statement conflicted with the FOREIGN KEY constraint "FKUSERS_AVAT731248". The conflict occurred in database "gk314", table "gk314.USERS", column 'userId'.
The statement has been terminated.

Msg 547, Level 16, State 0, Line 2
The INSERT statement conflicted with the FOREIGN KEY constraint "FKUSERS_AVAT731248". The conflict occurred in database "gk314", table "gk314.USERS", column 'userId'.
The statement has been terminated.


Help please!!!!





asked 3 mins ago


2 Answers



Vote count:

0




This means that there's a table, gk314.USERS, that doesn't have a userId that matches the userId you're attempting to add to USERS_AVATAR. Check the USERS table and add users with userId 1 and 2, and then you should be able to add to the USERS_AVATAR table.



answered 59 secs ago

Adam V

2,864


Vote count:

0




Before inserting userIds 1 and 2 into USERS_AVATAR, you MUST first insert them into table USERS. That is what the FOREIGN KEY constraint is requiring.



answered 52 secs ago

Russ

1,562





The INSERT statement conflicted with the FOREIGN KEY constraint. The conflict occurred in database

Aucun commentaire:

Enregistrer un commentaire