I have a new table that has a foreign key constraint to an old, legacy table. The old table is populated with a great deal of data, but when I try to add a row to the new table that references a row in the old table, I get a Cannot add or update a child row: a foreign key constraint fails
error.
How do I add rows to the new table that reference rows in the old table?
EDIT Here are two queries I tried:
mysql> select user_pk from users where username = 'test_user';
+---------+
| user_pk |
+---------+
| 123766 |
+---------+
1 row in set (0.00 sec)
mysql> insert into uservisit (user_id) values (123766);
ERROR 1452 (23000): Cannot add or update a child row: a foreign key constraint fails (`test_database`.`uservisit`, CONSTRAINT `user_id_refs_user_pk_37c3999c` FOREIGN KEY (`user_id`) REFERENCES `users` (`user_pk`))
Am I doing something wrong?