Open In App

How to Fix – NoSuchTable: Table doesn’t exist in the database.

This article helps you to understand the “NoSuchTable: Table doesn’t exist in the database” error, why it occurs and possible solutions you can try out to fix the errors.

What is No Such Table Exist Error?

Error message “NoSuchTable: Table doesn’t exist in the database” appears when you have created and defined some tables in your database. But maybe for some reason your table doesn’t get created or cannot be found. When you try to perform certain actions on that particular table, this message will pop out.



These errors can appear in various DBMS systems like MySQL, PostgreSQL, SQLite etc.

Syntax: NoSuchTable: “User” table doesn’t exist in the database.



Causes of Error

How to Solve NoSuchTable Error?

Lets perform some steps practically to fix this error. Tools used while performing below steps might differ in your case but solutions are applicable for all databases.

Check to Avoid Basic Mistakes

Lets try out some approaches. if you made some silly mistakes that will be get cleared by following these approaches.

Verify DB Connection

Check if you have successfully connected with your database. Sometimes we miss our some settings. Verify you have entered host name, port, connection string, username, password correctly.

Check for Tables

Ensure that you have created the table. some database systems are case sensitives So while creating and performing operations on table verify that you are using same table name in same format.

Check Database Logs

If you have successfully connected to correct database. Then open GUI tool of particular database or terminal to check the database logs. Check if you mistakly dropped or renamed your table.

Permission Issues

If you are not able to track the recent changes or facing the problem related to permissions. you can contact to your database administrator in this case.

Check Table Existence

Show Tables;

Flush the Tables

In DBMS, there is a command to reload the schema of table from disk instead of using cache. it may happen new tables are not getting reflected in your database. Thus you can try this.

USE my_db;

FLUSH TABLES;

This is an example command you can use if you are working with MySQL command. For other databases the command may vary.

Check Database Logs

It might happen in your case the table gets dropped or renamed. so now we will check that if some operation has been performed or not.

You will have to first activate query logging and then you will a see a list of operations performed on the connected database tables.

Check Migrations

If you are using object relational mapper tool while dealing with database operations. In case you dropped or deleted any table and recreated it. while doing this some times it does not get migrated correctly and might lead to this error.

Django Framework Example

You may try deleting the database file and all migrations folder present in your project. After running the project database file will get recreated. Migrate the changes and check if the error fixed or not.

If still you are facing the same error. Try migrating each apps separately. This might solve the error.

# incase if you are dealing with Django ORM. python manage.py makemigrations app_name

Delete the tables and Recreate it

If you tried out the previous solutions still it is not working out. then you can delete your database schema and tables and recreate them. Ensure that you are defining the attributes and fields properly.

In Summary of this article, we have covered the introduction of the error, possible approaches you can take to avoid silly mistakes and finally some practically performed solutions for the error. Hope so this will help you to solve the error.

Article Tags :