已经解决了:
[已解决]Flask运行出错:ImportError: No module named flask_sqlalchemy
但是运行又警告:
(SIPEvents) ➜ SIPEvents python Python 2.7.12 (default, Aug 15 2016, 11:09:04) [GCC 4.4.7 20120313 (Red Hat 4.4.7-17)] on linux2 Type “help”, “copyright”, “credits” or “license” for more information. >>> from app import db /root/Envs/SIPEvents/lib/python2.7/site-packages/flask_sqlalchemy/__init__.py:800: UserWarning: 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 will be disabled by default in the future. Set it to True to suppress this warning.’) <div–<—————————————————————————— DEBUG in app [app.py:35]: db=<SQLAlchemy engine=’sqlite:////usr/share/nginx/html/SIPEvents/sipevents.db’> <div–<—————————————————————————— >>> |
相关代码:
from flask_sqlalchemy import SQLAlchemy |
搜:
UserWarning: SQLALCHEMY_TRACK_MODIFICATIONS adds significant overhead and will be disabled by default in the future
参考:
python – How do I know if I can disable SQLALCHEMY_TRACK_MODIFICATIONS? – Stack Overflow
去添加对应的配置:
SQLALCHEMY_TRACK_MODIFICATIONS = False
(SIPEvents) ➜ SIPEvents cat instance/config.py SQLALCHEMY_DATABASE_URI = ‘sqlite:////usr/share/nginx/html/SIPEvents/sipevents.db’ SQLALCHEMY_TRACK_MODIFICATIONS = False |
然后再去运行,就没有了这个警告了:
(SIPEvents) ➜ SIPEvents python Python 2.7.12 (default, Aug 15 2016, 11:09:04) [GCC 4.4.7 20120313 (Red Hat 4.4.7-17)] on linux2 Type “help”, “copyright”, “credits” or “license” for more information. >>> from app import db <div–<—————————————————————————— DEBUG in app [app.py:35]: db=<SQLAlchemy engine=’sqlite:////usr/share/nginx/html/SIPEvents/sipevents.db’> <div–<—————————————————————————— >>> |
[总结]
如果你的应用没有使用Flask-SQLAlchemy的事件系统,那么可以放心的去:
在对应的配置文件添加:
SQLALCHEMY_TRACK_MODIFICATIONS = False |
即可消除此警告。
转载请注明:在路上 » [已解决]Flask中使用sqlalchemy出现警告:UserWarning SQLALCHEMY_TRACK_MODIFICATIONS adds significant overhead