Forums

sqlite: database not found.

I am connecting to a .db file using sqlite3 file, and it works perfectly on localhost. It doesn't work on python anywhere though, and I am 100% sure the database exists (I can access it through terminal properly). What is the problem? I am using it for a Flask project.

THIS_FOLDER = os.path.dirname(os.path.abspath(__file__))
db_location = os.path.join(THIS_FOLDER, 'finance.db')

con = sqlite3.connect(db_location, check_same_thread=False)
con.row_factory = sqlite3.Row

cur = con.cursor()

This is the code inside the main file.

2022-06-02 18:24:44,998: Exception on /login [POST]
Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/flask/app.py", line 2051, in wsgi_app
    response = self.full_dispatch_request()
  File "/usr/local/lib/python3.9/site-packages/flask/app.py", line 1501, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/usr/local/lib/python3.9/site-packages/flask/app.py", line 1499, in full_dispatch_request
    rv = self.dispatch_request()
  File "/usr/local/lib/python3.9/site-packages/flask/app.py", line 1485, in dispatch_request
    return self.ensure_sync(self.view_functions[rule.endpoint])(**req.view_args)
  File "/home/siddharthrout/mysite/app.py", line 60, in login
sqlite3.OperationalError: no such table: users

This is the full error message.

Looks like the tables were not created correctly? Do you use migrations?