This has me baffled, here's hoping someone can help.
insert into `shelter_pages` (`userid`,`relid`)
select :userid, `id` from `shelter` where `stage`='egg' order by rand() limit 30
SQLSTATE: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (`db_name`.`shelter_pages`, CONSTRAINT `shelter_pages_ibfk_2` FOREIGN KEY (`relid`) REFERENCES `shelter` (`id`) ON DELETE CASCADE ON UPDATE CASCADE)
This is likely happening because you have your transaction isolation level set to "dirty read" (i.e.
READ UNCOMMITTED). This means that the
SELECT could be reading uncommitted data that would fail the foreign key constraints during the