close

[Solved] Python sqlite3.Operational: no such table:

Hello Guys, How are you all? Hope You all Are Fine. Today I get the following error Python sqlite3.Operational: no such table: in python. So Here I am Explain to you all the possible solutions here.

Without wasting your time, Let’s start This Article to Solve This Error.

How Python sqlite3.Operational: no such table: Error Occurs?

Today I get the following error Python sqlite3.Operational: no such table: in python.

How To Solve Python sqlite3.Operational: no such table: Error ?

  1. How To Solve Python sqlite3.Operational: no such table: Error ?

    To Solve Python sqlite3.Operational: no such table: Error Use an absolute path for your database file. You can base it on the absolute path of your script:

  2. Python sqlite3.Operational: no such table:

    To Solve Python sqlite3.Operational: no such table: Error Use an absolute path for your database file. You can base it on the absolute path of your script:

Solution 1

You are assuming that the current working directory is the same as the directory your script lives in. It is not an assumption you can make. Your script is opening a new database in a different directory, one that is empty.

Use an absolute path for your database file. You can base it on the absolute path of your script:

import os.path

BASE_DIR = os.path.dirname(os.path.abspath(__file__))
db_path = os.path.join(BASE_DIR, "PupilPremiumTable.db")
with sqlite3.connect(db_path) as db:

You can verify what the current working directory is with os.getcwd() if you want to figure out where instead you are opening the new database file; you probably want to clean up the extra file you created there.

Solution 2


I had the same problem and here’s how I solved it.

  1. I killed the server by pressing Ctrl+C
  2. I deleted the pychache folder. You’ll find this folder in your project folder.
  3. I deleted the sqlite db.
  4. I made migrations with python manage.py makemigrations <app_name> where <app_name> is the specific app that contains the model that’s causing the error. In my case it was the mail app so I ran python manage.py makemigrations app.
  5. I migrated in the normal way.
  6. Then I started the server and it was all solved.

I believe the issue is as Jorge Cardenas said:

Maybe you are loading views or queries to database but you haven´t granted enough time for Django to migrate the models to DB. That’s why the “table doesn’t exist”.

Summery

It’s all About this issue. Hope all solution helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which solution worked for you? Thank You.

Also, Read