-
Notifications
You must be signed in to change notification settings - Fork 473
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
RuntimeError: Working outside of application context. when creating SQLite DB #16
Comments
you can add
Now try to run direct app.py file |
Is your virtual environment active in the terminal you start the REPL in? The error hints that you're attempting to execute code outside of its working context which sounds like an environment issue to me |
For those of you who faced the database creation error, do the following:
it should be created under instance directory after those commands. |
call manually in the flask shell , this is because I think in Flask-SQLAlchemy to access the DB db.engine and db.session requires an active Flask app context , when you run the CLI command a context will be pushed automatically.
|
def create_tables(): just add this lines after class Todo(db.Model) , after runing the app once put them as comment this worked for me |
macOS Venture 13.4
Python 3.11.3
>>> from app import db >>> db.create_all()
returns
when trying to create db from following code:
any idea?
The text was updated successfully, but these errors were encountered: