我已经遇到这个问题几个小时了。在 SQL Server
中,我运行了以下查询:
INSERT INTO USERS_AVATAR(userId, avatId) VALUES ('1', '213');
INSERT INTO USERS_AVATAR(userId, avatId) VALUES ('2', '312');
但显示的消息显示:
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'.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'.
请帮忙!
最佳答案
在将用户 ID 1
和 2
插入 USERS_AVATAR
之前,必须先将它们插入表 USERS
中。这就是 FOREIGN KEY 约束所需要的。
关于sql - INSERT 语句与 FOREIGN KEY 约束冲突。数据库发生冲突,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29235773/