Flask,SQLAlchemy:KeyError:"SQLALCHEMY_TRACK_MODIFICATIONS" [英] Flask, SQLAlchemy : KeyError: 'SQLALCHEMY_TRACK_MODIFICATIONS'

查看:309
本文介绍了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

这篇关于Flask,SQLAlchemy:KeyError:"SQLALCHEMY_TRACK_MODIFICATIONS"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆