1051ERRORTier 1 — Safe✅ HIGH confidence

Unknown table

Category: SchemaVersions: All MariaDB / MySQL versions

What this means

Error 1051 (SQLSTATE 42S02) is raised by DROP TABLE when the specified table does not exist. Unlike error 1146 which is raised by DML queries, 1051 is specifically from DROP TABLE.

Why it happens

  1. 1Attempting to DROP TABLE a table that was already dropped
  2. 2Running a rollback migration out of order
  3. 3Typo in the table name

How to reproduce

DROP TABLE is called on a non-existent table.

trigger — this will ERROR
DROP TABLE nonexistent_table;
ERROR 1051 (42S02): Unknown table 'mydb.nonexistent_table'

Fix 1: Use IF EXISTS

In idempotent down-migrations.

fix
DROP TABLE IF EXISTS nonexistent_table;

Why this works

IF EXISTS causes DROP TABLE to silently succeed (with a Note warning) if the table does not exist, making the drop idempotent.

What not to do

Ignore the error in CI/CD pipelines without investigation

Why it's wrong: If an expected table is missing it may indicate that a previous migration partially failed, leaving the schema in an inconsistent state.

Version notes

All versionsDROP TABLE IF EXISTS is available in all supported versions.

Sources

📚 Official docs: https://mariadb.com/kb/en/drop-table/

🔧 Source ref: MariaDB Server error code 1051 / ER_BAD_TABLE_ERROR

📖 Further reading: MariaDB DROP TABLE

Confidence assessment

✅ HIGH confidence

Stable.

See also

📄 Reference pages

DROP TABLE IF EXISTS
⚙️ This error reference was generated with AI assistance and reviewed for accuracy. Examples are provided to illustrate common scenarios and may not cover every case. Always test fixes in a development environment before applying to production. Spotted an error? Suggest a correction →