LoginSignup
14
3

More than 1 year has passed since last update.

[Flask] [備忘録]RuntimeError: Working outside of application context.でツボった

Posted at

こちらの記事を見ながらFlaskとSQLalchemyを用いてログイン機能を作成していたところ以下のようなエラーが出て2時間くらいツボったのでその解決方法を備忘録的にメモしておきます!もっといい解決方法知っている方がいましたらコメントで教えていただけますと幸いです!
https://qiita.com/yuuki-h/items/47135ea7a07d0c994275

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.

ターミナルで以下のコマンドを順に実行してみましょう!

ターミナル
% python
>>> from app import app
>>> from app import db
>>> with app.app_context():
...    db.create_all()
>>> exit()

これで解決しました!

>>> with app.app_context():
...    db.create_all()

の2行目はtabキーでインデントを揃えるようにしてください!

14
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
14
3