1146
MariaDBERRORCommonSchemaHIGH confidence

Table doesn't exist

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
trigger — this will error
SELECT * FROM user_sessions;  -- table doesn't exist

expected output

ERROR 1146 (42S02): Table 'mydb.user_sessions' doesn't exist

Fix 1

Run the missing migration

WHEN When the table should exist but was never created.

Run the missing migration
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 When troubleshooting what tables actually exist.

Verify available tables
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

Manually created tables diverge from the tracked migration state, causing future migrations to fail and making environment parity impossible.

Version notes
All versions

Stable error code.

Sources
Official documentation ↗

MariaDB Server error code 1146 / ER_NO_SUCH_TABLE

MariaDB SHOW TABLES

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

← All MariaDB errors