From 73c4d6707e401ffe4eed3286ea52d038546ba0a1 Mon Sep 17 00:00:00 2001 From: Liam Nguyen Date: Thu, 1 Dec 2022 13:01:28 -0500 Subject: [PATCH] Added terminal solution to initiate db instance --- README.md | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 2b135616d..85212bd86 100644 --- a/README.md +++ b/README.md @@ -1 +1,12 @@ -# code_snippets \ No newline at end of file +# 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() + ``` \ No newline at end of file