我在尝试使用python运行sqlite数据库时遇到了这个错误



运行db:时出现此错误

UserWarning: Neither SQLALCHEMY_DATABASE_URI nor SQLALCHEMY_BINDS is set. Defaulting SQLALCHEMY_DATABASE_URI to "sqlite:///:memory:".
warnings.warn(

它说问题出在这里:

def init_app(self, app):
"""This callback can be used to initialize an application for the
use with this database setup.  Never use a database in the context
of an application not initialized that way or connections will
leak.
"""
if (
'SQLALCHEMY_DATABASE_URI' not in app.config and
'SQLALCHEMY_BINDS' not in app.config
):
warnings.warn(
'Neither SQLALCHEMY_DATABASE_URI nor SQLALCHEMY_BINDS is set. '
'Defaulting SQLALCHEMY_DATABASE_URI to "sqlite:///:memory:".'
)

在我们看到导致错误的代码之前,我不能确定这是否是正确的答案,如果答案是错误的,我会更新我的答案,但是当你在配置应用程序之前调用init_app()时,这个问题往往会出现,当它试图找到它时,它是空白的,因为你没有配置它,所以它会使用默认的sqlite:///:memory:

但请更新您的帖子,包括您的代码,这样人们将能够提供帮助,而不是显示导入的代码

相关内容

最新更新