Error 1213 means two of your transactions are waiting on each other forever, so MySQL kills one of them. This guide shows how to reproduce a deadlock, read the evidence MySQL leaves behind, and fix it for good with consistent lock order and safe retries.