最近在学“数据库配置”这一部分,试着运行示例5-1的程序时解释器提示出错:
$venvlibsite-packagesflask_sqlalchemy\__init__.py:800: U
serWarning: SQLALCHEMY_TRACK_MODIFICATIONS adds significant overhead and will be
disabled by default in the future. Set it to True to suppress this warning.
warnings.warn('SQLALCHEMY_TRACK_MODIFICATIONS adds significant overhead and wi
ll be disabled by default in the future. Set it to True to suppress this warnin
g.')
在网上查了一下,也有人碰到过这个问题,发现是sqlalchemy版本更新了,有一些配置改变了。
app= Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI']=
'sqlite:///'+os.path.join(basedir, 'data.sqlite')
app.config['SQLALCHEMY_COMMIT_ON_TEARDOWN']= True
上面是书上给的代码,官方文档中SQLALCHEMY_COMMIT_ON_TEARDOWN 不用配置了,要新配置SQLALCHEMY_COMMIT_ON_TEARDOWN,给它设置为True。
app= Flask(__name__) app.config['SQLALCHEMY_DATABASE_URI']= 'sqlite:///'+os.path.join(basedir, 'data.sqlite') app.config['SQLALCHEMY_TRACK_MODIFICATIONS']= True