creating a database outside the application context

Flask-SQLAlchemy only needs an app context to operate. You can create an app context manually.

app = create_app(env)
ctx = app.app_context()
ctx.push()

# your code here

ctx.pop()

This is from the docs here and here.

Leave a Comment