flask sqlitedb connection error工作在应用程序上下文之外


>>> from app import db
>>> db.create_all()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:UserskinutAppDataLocalProgramsPythonPython311Libsite-packagesflask_sqlalchemyextension.py", line 868, in create_all
self._call_for_binds(bind_key, "create_all")
File "C:UserskinutAppDataLocalProgramsPythonPython311Libsite-packagesflask_sqlalchemyextension.py", line 839, in _call_for_binds
engine = self.engines[key]
^^^^^^^^^^^^
File "C:UserskinutAppDataLocalProgramsPythonPython311Libsite-packagesflask_sqlalchemyextension.py", line 628, in engines
app = current_app._get_current_object()  # type: ignore[attr-defined]
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:UserskinutAppDataLocalProgramsPythonPython311Libsite-packageswerkzeuglocal.py", line 513, in _get_current_object
raise RuntimeError(unbound_message) from None
RuntimeError: Working outside of application context.

我在尝试创建sqlite数据库时遇到这个错误

期望不返回,只是创建数据库

from mycode import app
from mycode import db
with app.app_context():
db.create_all()

相关内容

  • 没有找到相关文章

最新更新