Skip to content
ERROR 1146 (42S02): Table '...' doesn't exist

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

DodaTech 2 min read

MySQL ERROR 1146 (42S02) means the server cannot find the table you referenced in your query. This usually happens due to a typo, wrong database context, or the table never being created.

What It Means

The table name in your SQL statement does not match any table in the current or specified database. MySQL includes the full dotted name (database.table) in the error to help debug.

Why It Happens

  • Typo in the table name in your query or ORM model.
  • The table exists in a different database than the one currently selected.
  • The table was dropped or the migration failed to run.
  • Wrong database selected in the connection.

How to Fix It

1. List tables in the current database

SHOW TABLES;

If you see your table listed, check for case mismatches or hidden characters.

2. Verify and switch to the correct database

SELECT DATABASE();
USE your_database_name;
SHOW TABLES;

Your table might exist in a different database. Qualify the name explicitly:

SELECT * FROM other_db.your_table;

3. Create the missing table

If the table genuinely does not exist, create it:

CREATE TABLE users (
    id INT AUTO_INCREMENT PRIMARY KEY,
    email VARCHAR(255) NOT NULL,
    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);

For production, run pending migrations:

# Laravel
php artisan migrate

# Django
python manage.py migrate

# Raw SQL file
mysql -u root -p mydb < schema.sql

4. Check for table name quoting issues

Backticks are optional unless the name is a reserved word:

-- Correct
SELECT * FROM users;

-- Also correct
SELECT * FROM `users`;

-- Wrong (reserved word without backticks)
SELECT * FROM order;
-- Fix
SELECT * FROM `order`;

FAQ

Can innodb data dictionary cache cause this error?
Yes. If the table was created outside the current session, run FLUSH TABLES; or reconnect. In rare cases, restart MySQL to clear the cached table metadata.
Why does SHOW TABLES show the table but my query still fails?
You may not have SELECT privilege on that table, or the table resides in a different database. Check with SHOW GRANTS; and verify you ran USE db_name; first.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro