1051
MySQLERRORCommonSchemaHIGH confidence

Unknown table

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
trigger — this will error
DROP TABLE nonexistent_table;

expected output

ERROR 1051 (42S02): Unknown table 'mydb.nonexistent_table'

Fix

Use IF EXISTS

WHEN In idempotent down-migrations.

Use IF EXISTS
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

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 versions

DROP TABLE IF EXISTS is available in all supported versions.

Sources
Official documentation ↗

MariaDB Server error code 1051 / ER_BAD_TABLE_ERROR

MariaDB DROP TABLE

Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev

← All MySQL errors