From 275df31213fdc49990694cd0b4bb72cefc258ca3 Mon Sep 17 00:00:00 2001 From: "Manuel Weiser (aider)" Date: Mon, 2 Sep 2024 09:32:28 +0200 Subject: [PATCH] fix: ensure database is initialized before operations to resolve OperationalError --- game_collection/app.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/game_collection/app.py b/game_collection/app.py index adf281a..ec0b2a0 100644 --- a/game_collection/app.py +++ b/game_collection/app.py @@ -9,7 +9,7 @@ app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False db.init_app(app) with app.app_context(): - init_db() + init_db() # Ensure the database is initialized before any operations @app.route('/games', methods=['POST']) def add_game(): @@ -38,4 +38,6 @@ def get_games(): } for game in games]) if __name__ == '__main__': + with app.app_context(): + init_db() # Ensure the database is initialized when the app starts app.run(debug=True)