<p>MySQL raises ER_DISCARD_FK_CHECKS_RUNNING when you attempt to discard a table or tablespace while a foreign key check is still running.</p>
<p>MySQL Error 1807: ER_DISCARD_FK_CHECKS_RUNNING appears when you run ALTER TABLE ... DISCARD TABLESPACE or a DROP/TRUNCATE command while MySQL is still performing foreign key checks on the target table. Finish or kill the running check, then retry the statement to fix the issue.</p>
There is a foreign key check running on table '%s'.
MySQL throws error code 1807 with condition ER_DISCARD_FK_CHECKS_RUNNING and message "There is a foreign key check running on table '%s'." when you try to discard a table or its tablespace while MySQL is actively validating foreign key constraints on that table.
The operation fails because discarding a tablespace or dropping data would invalidate ongoing referential integrity checks, risking corruption. MySQL blocks the request until those checks finish or are stopped.
The error occurs most often during ALTER TABLE ... DISCARD TABLESPACE, DROP TABLE, or TRUNCATE TABLE commands executed while foreign key verification is still running after a previous DDL statement on the same or a parent table.
Large tables with many foreign keys need extra time for validation. Concurrent sessions or automated routines that issue discard commands too quickly trigger the conflict and result in ER_DISCARD_FK_CHECKS_RUNNING.
First, identify the session performing the foreign key check using INFORMATION_SCHEMA.PROCESSLIST or PERFORMANCE_SCHEMA.setup_instruments. Wait for that process to finish if possible. For urgent maintenance, you may kill the blocking thread, then rerun the discard command.
Another approach is to disable foreign key checks temporarily, but this should only be done in isolated environments where referential integrity is guaranteed by other means.
Scenario: You import data with ALTER TABLE ... IMPORT TABLESPACE immediately after DISCARD TABLESPACE. Solution: Insert a wait loop that polls INFORMATION_SCHEMA.INNODB_TRX for running FK checks before issuing the DISCARD.
Scenario: Automated deployment scripts run parallel schema changes on parent and child tables. Solution: Serialize DDL operations or use pt-online-schema-change to avoid collisions.
Schedule heavy DDL during low-traffic windows and allow MySQL to finish integrity checks before launching the next step. Monitor running processes and add explicit waits in automation scripts.
Tools like Galaxy provide execution history and lock-aware insights, helping teams coordinate DDL changes and avoid conflicts that lead to ER_DISCARD_FK_CHECKS_RUNNING.
Error 1553 (ER_FK_CHECK_RUNNING): Similar conflict but arises while dropping a database. Solution: Wait or kill FK check thread before dropping.
Error 150: Foreign key constraint fails. Unlike 1807, this signals an actual referential integrity violation rather than a timing conflict. Fix by correcting data or constraint definitions.
Large tables or complex FK relationships can take minutes to verify, leaving checks active when the next DDL arrives.
Automated pipelines running multiple ALTER TABLE statements simultaneously often overlap and trigger the error.
Scripts that discard and import tablespaces back-to-back may not wait for the FK check that starts during IMPORT to finish.
Occurs when dropping a database during active FK checks. Wait or kill the check thread.
Indicates data violates a declared FK. Fix by cleaning data or adjusting constraints.
Arises during large index creation and may coincide with FK checks. Reduce column size or change index type.
Killing only the checking thread is safe because it rolls back its work, but ensure no dependent operations are running.
No. Disabling globally can hide data issues. Use it only for bulk loads in isolated windows.
Duration depends on table size and hardware. Millions of rows with multiple indexes may require minutes or hours.
Galaxy surfaces lock states and foreign key check progress inside its SQL editor, letting teams sequence operations and prevent clashes.