正确命令后使用 python aerich 出现错误
我有 aerich 配置问题:
我有 app/database.py
文件,其中包含以下内容:
TORTOISE_ORM = {
"connections": {"default": "postgres://..."},
"apps": {
"models": {
"models": ["app.models", "aerich.models"],
"default_connection": "default",
},
},
}
此外,我还有一个 python 包,其中包含位于 app/models/... 的乌龟表。
。 我正在尝试使用以下命令创建第一个迁移文件:
aerich init -t app.database.TORTOISE_ORM
,并且我正在pyproject.toml
内部获取数据:
[tool.aerich]
tortoise_orm = "app.database.TORTOISE_ORM"
location = "./migrations"
src_folder = "./."
- 之后我尝试运行
aerich init-db
,但收到错误:tortoise.exceptions.ConfigurationError:找不到模块“app.models”
我尝试了很多不同的变体来更改此配置,但得到了相同的错误。 aerich的版本==^0.6.2
大家知道这是怎么回事吗?
I have the problem with aerich configs:
I have the app/database.py
file with the next content:
TORTOISE_ORM = {
"connections": {"default": "postgres://..."},
"apps": {
"models": {
"models": ["app.models", "aerich.models"],
"default_connection": "default",
},
},
}
Also I have a python package with tortoise tables located in app/models/...
.
I'm trying to create first migrations file, using the next commands:
aerich init -t app.database.TORTOISE_ORM
and I'm getting data inside of mypyproject.toml
:
[tool.aerich]
tortoise_orm = "app.database.TORTOISE_ORM"
location = "./migrations"
src_folder = "./."
- After it I'm trying to run
aerich init-db
, but I'm getting an error:tortoise.exceptions.ConfigurationError: Module "app.models" not found
I tried a lot of different variants to change this configs but getting the same error. Version of aerich==^0.6.2
Does everybody know what's wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
字典中的 models 变量应包含包含数据库模型的模块。根据您的描述,您有一个包含模型文件的模型目录。例如,您有 hello.py,它在 models 文件夹中包含模型类,那么您需要提供“app.models.hello”而不仅仅是“app.models”。
The models variable in the dictionary should contain the module containing the Model for your database. As per your description, you have a models directory that contains files with the Model. For example, you have hello.py which contains model classes inside the models folder then you need to provide "app.models.hello" instead of just "app.models".
我看到您也在 aerich Github 存储库中提出了问题。在那里给出了答案,但为了完整起见,我将在这里重复一遍。
刚刚遇到这个
tortoise.exceptions.ConfigurationError: Module;我自己没有找到
错误。使用调试器,我发现问题(至少在我的情况下)实际上并不是找不到模块。引发的ImportError
(导致ConfigurationError
)实际上暗示了循环导入的问题。奇怪的是,我在使用应用程序本身(运行相同的导入)时没有遇到这个循环导入问题,但在使用 aerich 时我确实遇到了这个问题...长话短说:
ImportError
中的msg
),因为“找不到模块”可能根本不是实际问题。I saw that you also asked this question in the aerich Github repo. Gave an answer there, but I'll repeat it here for completeness.
Just ran into this
tortoise.exceptions.ConfigurationError: Module <x> not found
error myself. Using a debugger, I found out that the problem - at least in my case - was actually not that the module could not be found. TheImportError
raised (which leads to theConfigurationError
) was in fact hinting towards a problem with circular imports. Weirdly enough I don't get this circular import problem when using the app itself (which runs the same imports), but I do get it when using aerich...Long story short:
msg
from theImportError
) as "Module not found" might simply not be the actual problem.