MySQL cannot complete a DDL statement because another session still references the target table.
MySQL error ER_TABLE_REFERENCED (3193) occurs when you attempt to drop, rename, truncate, or alter a table that is currently referenced by another connection or foreign key constraint. End or commit the blocking session, or temporarily disable FOREIGN_KEY_CHECKS, to complete the operation.
ER_TABLE_REFERENCED
MySQL raises error 3193 with message "Cannot complete the operation because table is referenced" when a DDL statement tries to drop, rename, truncate, or alter a table that another connection has locked or that is still referenced by a foreign key in the current transaction.
The server blocks the operation to protect referential integrity. The error appears from MySQL 5.7.14 onward and can surface in interactive sessions, automated migrations, or ALTER TABLE scripts.
The most common cause is an open foreign key lock in another session holding a metadata or row lock on the parent or child table.
Long running transactions or uncommitted SELECT ... FOR UPDATE statements often linger and keep the reference active.
Concurrent DDL on related tables, such as adding an index on a parent table while another session drops the child table, also triggers the error.
Misordered migration scripts can create circular FK references that leave dangling dependencies until the full sequence runs.
Identify and end the blocking session using performance_schema or SHOW ENGINE INNODB STATUS, then re-run the DDL once the lock is released.
If the reference is purely at schema level, temporarily disable FOREIGN_KEY_CHECKS for the session, perform the change, then re-enable the check.
When dropping both parent and child tables, always drop the child tables first to avoid dependency conflicts.
Altering a child table while a reporting connection holds a metadata lock on the parent: close the reporting connection or wait for it to finish.
Renaming a table in a migration script: wrap statements in a single transaction and commit as soon as possible.
Bulk cleanup using TRUNCATE: use DELETE with smaller batches if truncation is blocked by FK locks.
Keep transactions short and commit promptly to release metadata locks.
Run disruptive DDL during maintenance windows with minimal concurrent traffic.
Order migration scripts from leaf child tables up to root parent tables.
Use MySQL SET lock_wait_timeout to fail fast rather than hang.
Galaxy shows live locks so you can terminate blocking queries before running DDL, reducing the chance of ER_TABLE_REFERENCED.
ER_ROW_IS_REFERENCED_2 (1451) appears when deleting a referenced row. Delete from the child table first or use ON DELETE CASCADE.
ER_CANNOT_ADD_FOREIGN (1215) occurs when adding a foreign key that violates existing data. Clean the data or align column types.
ER_LOCK_WAIT_TIMEOUT (1205) surfaces when waiting for the same metadata locks; shorten competing transactions or raise lock_wait_timeout.
Another connection holds a metadata or row lock on the parent or child table, preventing DDL on the table you target.
Uncommitted transactions keep references active, blocking any schema change until commit or rollback.
Scripts that attempt to drop or alter parent tables before children leave active references and trigger the error.
Simultaneous ALTER TABLE operations on tables with relationships can deadlock and surface as ER_TABLE_REFERENCED.
Raised when a DELETE or UPDATE would break a foreign key constraint.
Occurs while adding a foreign key that conflicts with existing data or index definitions.
Raised when a session times out waiting for a metadata or row lock.
Appears when inserting or updating a foreign key column that lacks a matching parent row.
Run SHOW ENGINE INNODB STATUS or query performance_schema.metadata_locks to see which thread holds a lock on the table.
Disable checks only in controlled scripts where you preserve referential integrity and re-enable them immediately.
You can wait until the blocking transaction commits, but long waits hurt uptime. Setting lock_wait_timeout protects the application.
Galaxy displays live locks and lets you end blocking sessions from the UI before submitting DDL, reducing the chance of ER_TABLE_REFERENCED.