Skip to content

Conversation

nimstepf
Copy link

Patch for RuntimeError in Python/Flask_Blog:

RuntimeError: Working outside of application context.

This typically means that you attempted to use functionality that needed the current application. 
To solve this, set up an application context with app.app_context(). See the documentation for more information.

Since Flask-SQLAlchemy 3.0, all access to db.engine (and db.session) requires an active Flask application context. db.create_all uses db.engine, so it requires an app context. The solution was proposed by davidism on stackoverflow (https://stackoverflow.com/questions/73961938). More information can be found in the docs (https://flask.palletsprojects.com/en/2.3.x/appcontext/)

Changes Made:

  • Added with app.app_context(): to the relevant instances of the __init__.py file to provide the necessary application context.
  • Verified and tested the changes to ensure they resolve the runtime error and do not introduce any new issues.

Thank you for your exceptional tutorials, as they have greatly enhanced my understanding in Python. Please review and merge this pull request at your earliest convenience. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant