Django 表名称
我正在重构 Django 应用程序。具体来说,我有一个带有大 models.py
文件的应用程序,我试图将其拆分为一堆小文件,例如
myapp/
models/
__init__.py
somemodels.py
someothers.py
somemore.py
...
models/__init__.py
中的 和从所有其他文件导入所有模型,这样我就不必更改客户端代码。
问题是 Django 现在抱怨表名。模型 Foo
的表曾经是 myapp_foo
,但 Django 现在似乎会查找表 myapp.models_foo
。也就是说,它似乎使用定义模型的包而不是其应用程序作为前缀(当然 myapp.models
没有注册为 Django 应用程序)。
我知道我可以手动设置每个模型的表名称,但是有没有办法避免这种情况并告诉 Django 这些模型实际上是
myapp
的一部分?
I am refactoring a Django application. Specifically, I have an application with a big models.py
file and I am trying to split it into a bunch of small files, like
myapp/
models/
__init__.py
somemodels.py
someothers.py
somemore.py
...
and in models/__init__.py
I import all models from all other files so that I do not have to change client code.
The problem is that Django now complains about table names. Table for model Foo
used to be myapp_foo
, but it seems that Django now looks for a table myapp.models_foo
. That is, it seems that it uses as prefix the package where the models are defined instead of their application (of course myapp.models
is not registered as a Django application).
I know I could manually set the table name for each and every models, but is there a way to avoid this and tell Django that these models are actually part of
myapp
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用
Meta.app_label
Use
Meta.app_label