tortoise-orm在fastapi的lifespan中访问数据库表时报for r in self._routers:TypeError: ‘NoneType‘ object is not it

解决:升级tortoise-orm到0.21.1以上版本,或使用github上的待发布版

poetry add 'tortoise-orm>=0.21.1' || poetry add 'git+https://github.com/tortoise/tortoise-orm.git'

或直接pip安装https://pip.pypa.io/en/stable/cli/pip_install/#examples

pip install --upgrade 'tortoise-orm>=0.21.1' || pip install --upgrade 'git+https://github.com/tortoise/tortoise-orm.git'

*注:pip安装时如果报443连接超时,可以用ssh的方式(本地公钥需配置到github里):

pip install --upgrade 'tortoise-orm>=0.21.1' || pip install --upgrade 'git+ssh://[email protected]/tortoise/tortoise-orm.git'

升级完成后,不再报错了

=====================================

如果还想消除warnning提示,可参照库文档的示例修改代码https://tortoise.github.io/examples/fastapi.html#main-py

你可能感兴趣的:(fastapi,python)