1146ERRORTier 1 — Safe✅ HIGH confidence

Table doesn't exist

Category: SchemaVersions: All MariaDB / MySQL versions

What this means

Error 1146 (SQLSTATE 42S02) is returned when a DML query (SELECT, INSERT, UPDATE, DELETE) references a table that does not exist in the current database. It is typically caused by a missing migration, a typo, or deploying application code before the corresponding database migration.

Why it happens

  1. 1A schema migration was not run before deploying application code that references the new table
  2. 2Typo in the table name in the query
  3. 3The application is connected to the wrong database (test vs. production)
  4. 4The table was accidentally dropped

How to reproduce

A SELECT references a table that was never created.

trigger — this will ERROR
SELECT * FROM user_sessions;  -- table doesn't exist
ERROR 1146 (42S02): Table 'mydb.user_sessions' doesn't exist

Fix 1: Run the missing migration

When the table should exist but was never created.

fix
CREATE TABLE user_sessions (
  id BIGINT PRIMARY KEY AUTO_INCREMENT,
  user_id INT NOT NULL,
  token VARCHAR(255) NOT NULL,
  created_at DATETIME DEFAULT CURRENT_TIMESTAMP
);

Why this works

Creating the table makes it available for DML queries. In a deployment workflow, ensure migrations are applied before the application starts.

Fix 2: Verify available tables

When troubleshooting what tables actually exist.

fix
SHOW TABLES;
-- or:
SELECT TABLE_NAME FROM information_schema.TABLES
WHERE TABLE_SCHEMA = DATABASE();

Why this works

SHOW TABLES lists all tables in the current database, allowing the exact name to be confirmed.

What not to do

Create the table manually in production outside the migration system

Why it's wrong: Manually created tables diverge from the tracked migration state, causing future migrations to fail and making environment parity impossible.

Version notes

All versionsStable error code.

Sources

📚 Official docs: https://mariadb.com/kb/en/show-tables/

🔧 Source ref: MariaDB Server error code 1146 / ER_NO_SUCH_TABLE

📖 Further reading: MariaDB SHOW TABLES

Confidence assessment

✅ HIGH confidence

Stable.

See also

📄 Reference pages

SHOW TABLESschema migrations
⚙️ 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 →