【错误】在抽取配置类以后,运行程序时出现错误:
UserWarning: Neither SQLALCHEMY_DATABASE_URI nor SQLALCHEMY_BINDS is set. Defaulting SQLALCHEMY_DATABASE_URI to "sqlite:///:memory:". 'Neither SQLALCHEMY_DATABASE_URI nor SQLALCHEMY_BINDS is set. '
FSADeprecationWarning: SQLALCHEMY_TRACK_MODIFICATIONS adds significant overhead and will be disabled by default in the future. Set it to True or False to suppress this warning. 'SQLALCHEMY_TRACK_MODIFICATIONS adds significant overhead and '
【分析】这个问题的原因在于,sqlalchemy的配置信息SQLALCHEMY_DATABASE_URI 和SQLALCHEMY_TRACK_MODIFICATIONS
也被抽了出去,所以在调用db.init_app()方法前应该先调用配置文件。
【解决】 app.config.from_object()先执行,然后再执行db.init_app()方法。 |