烧瓶,SQLAlchemy:KeyError:'SQLALCHEMY_TRACK_MODIFICATIONS' [英] Flask, SQLAlchemy : KeyError: 'SQLALCHEMY_TRACK_MODIFICATIONS'
问题描述
我正在尝试按照以下教程中的说明进行操作:
I am trying to follow the instructions from the following tutorial:
我从以下存储库下载了代码:
I downloaded the code from the following repo:
但是,当我在本地运行它并尝试向数据库添加内容时,出现以下错误:
However when I run it locally and try to add something to the database, I get the following error:
builtins.KeyError
KeyError: 'SQLALCHEMY_TRACK_MODIFICATIONS'
当我试图读取回溯时,我意识到即使我在配置文件中添加了一个变量 SQLALCHEMY_TRACK_MODIFICATIONS,一些 python 库文件也无法识别它的存在.
When I tried to read the traceback, I realised that even if I add a variable SQLALCHEMY_TRACK_MODIFICATIONS to the config file, some python library file is unable to recognise it exists.
看起来类似问题有另一个答案,但这更像是一个快速解决方案,而不是为什么会发生这种情况.
Looks like there is another answer to a similar question, but that was more like a quick fix, not why this is happening.
我想知道为什么会发生这种情况以及如何解决它.最好不要改变整个结构.
I would like to know why this is happening and how to fix it.Preferably without changing the whole structure.
非常感谢.
推荐答案
代码中有两个 app = Flask(__name__)
会导致这个问题.
Having two app = Flask(__name__)
in the code can cause this problem.
这就是我的情况,我删除了一个并将其保留在应用程序文件夹的 __init__.py
中,它起作用了
That was my case, I removed one and kept the one in the app's folder's __init__.py
, and it worked
这篇关于烧瓶,SQLAlchemy:KeyError:'SQLALCHEMY_TRACK_MODIFICATIONS'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!