MySQL error 1213 with SQLSTATE 40001 means InnoDB detected a transaction deadlock, chose a victim, and rolled that entire transaction back. Recovery therefore has two layers: retry the complete business transaction safely, then remove any repeatable lock-order pattern that makes the collision frequent. Raising innodb_lock_wait_timeout does not ...