Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

810
Views
Flask SQLAlchemy Can't Connect to Database

I have an app that I'm trying to connect to an SQLite DB. I have the db file in the same directory as the app but when I give command to create_all I get the following error:

sqlalchemy.exc.OperationalError: (sqlite3.OperationalError) unable to open database file (Background on this error at: https://sqlalche.me/e/14/e3q8)

This is a snippet of the code I am using.

    app.config['SECRET_KEY'] = 'dont look at me im a secret'
    app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:////C:/Users/me/PycharmProjects/thisproject/database.db'
    app.config['CSRF_ENABLED'] = True
    app.config['USER_ENABLE_EMAIL'] = False
    
    db = SQLAlchemy(app)
    
    
    class User(db.Model, UserMixin):
        id = db.Column(db.Integer, primary_key=True)
        username = db.Column(db.String(50), nullable=False, unique=True)
        password = db.Column(db.String(255), nullable=False, server_default='')
        active = db.Column(db.Boolean(), nullable=False, server_default='0')
    
    
    user_manager = UserManager(app, db, User)
over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

I believe truth is onto something here. It seems you are not specifying the path to the sqlite database correctly.

Your path should look like:

app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///C:\\Users\\me\\PycharmProjects\\thisproject\\database.db'
over 4 years ago · Santiago Trujillo Report

0

I had to change my app file name to 'app.py' then update the path to the db as follows:

app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///C:\\Users\\me\\PycharmProjects\\thisproject\\database.db'

In order to get this to work

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!