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.sql4. 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
Built by the developers of DodaTech
Doda Browser, DodaZIP & Durga Antivirus Pro