Query with a different value that does have a matching value in the foreign key table. mysql> INSERT INTO `users_sessions` VALUES(3,"fbfibdog1qumlj5mg4kstbagu7"," 18:37:15") ĮRROR 1452 (23000): Cannot add or update a child row: a foreign key constraint fails (`login`.`users_sessions`, CONSTRAINT `fk_sessions_id` FOREIGN KEY (`session_id`) REFERENCES `sessions` (`id`) ON DELETE CASCADE ON UPDATE CASCADE) ![]() clause, and got a better clue of what was happening. I tried running the same insert without the ON DUPLICATE KEY. Mysql> INSERT INTO `users_sessions` VALUES(3,"fbfibdog1qumlj5mg4kstbagu7"," 18:37:15") ON DUPLICATE KEY UPDATE last_accessed = " 18:37:15" ĮRROR 1062 (23000): Duplicate entry '3-fbfibdog1qumlj5mg4kstbagu7' for key 'PRIMARY' MySQL 5.6.3 apparently can't tell you the real reason for the error. TLDR: check your foreign keys, make sure the value exists in the parent table. How do I remove duplicate values from a column in MySQL?.How do I stop inserting duplicate records?. ![]()
0 Comments
Leave a Reply. |