0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

【解決】Flask 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().

Last updated at Posted at 2022-12-12

エラー

SQLalchemyを使ってデータベースを作成しようとしたところ以下のようなエラーを吐かれて次に進まない状態に、、、

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キーでインデントを揃えるようにしてください!

最後に

いかがでしたでしょうか?
少しでも誰かの助けになっていれば幸いです!

0
1
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
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?