The deployment looked quiet: an application request finished, its database connection returned to the pool, and a migration started. MariaDB then showed Waiting for table metadata lock while the ALTER TABLE made no visible progress. The missing fact is often outside the waiting statement. A transaction that ...
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 ...