Skip to content
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

Added terminal solution to initiate db instance for latest Flask_SQLAlchemy version #194

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,12 @@
# code_snippets
# code_snippets
## Flask-SQLAlchemy Version 3.0.0 update
- An active Flask application context is always required to access `session` and `engine`, regardless of if an application was passed to the constructor.
- Without an application context, creating db from terminal will raise `RuntimeError: Working outside of application context.` when you try to invoke `db.create_all()` from python interpreter.
- To counteract this issue, two solutions are presented:
1. `flask shell` offers made-ready app context and instance to create db.
2. Import app from FlaskBlog and create db under app context:
```
from flaskblog import app
with app.app_context():
db.create_all()
```