2

I have a multi-file flask project where I have a single model and a couple routes. Initially, the project was just a single app.py file and I was able to just run db.create_all() within that file. Now that I have complicated imports with my multi-file structure, I am wondering how I would go about creating the tables defined in my models.py file.

Application structure:

app/
    __init__.py
    config.py
    extensions.py
    models.py
    routes.py
.env
.flaskenv
Pipfile
Pipfile.lock
thebork
  • 29
  • 3

1 Answers1

0

I solved my problem with the following lines of code in my __init__.py file:

with app.app_context():
    db.create_all()

Before, I was simply calling db.create_all() but without the application context, it was failing. More information on this can be found at: https://flask-sqlalchemy.palletsprojects.com/en/2.x/contexts/.

thebork
  • 29
  • 3