syncdb不为嵌套模型创建表

时间:2013-09-28 14:13:32

标签: python mysql django

我有一个Django项目,其中包含以下结构的模型:

my_model/
├── __init__.py
├── models/
    ├── __init__.py
    ├── my_model.py
    ├── my_other_model.py

my_model.py和my_other_model.py,每个都包含模型,MyModel和MyOtherModel,在我的Django设置文件中,我已将此文件夹添加到我安装的应用列表中,如下所示:

INSTALLED_APPS = (
    ...
    'my_model',
    ...
)

现在,当我在项目上运行syncdb时,我希望两个模型都生成一个mysql表,但MyModel是唯一一个创建为mymodel_mymodel的表。我不知道如何让syncdb创建另一个模型,因为我希望得到另一个名为mymodel_myothermodel的表。

感谢您的帮助, 的Mattias

1 个答案:

答案 0 :(得分:2)

django<=1.6you must define app_label in your model's Meta,如果它不在models.py

中,则由syncdb接收

请注意,您可能正在运行django<=1.6,因为1.7尚未发布。


syncdb找到模型,您可能还需要在models/__init__.py中导入它们。

相关问题