几天前我开始学习Django,为了练习,我决定做一个小项目。你知道吗
完成模型之后,我尝试使用django数据库. 但是在运行python manage.py makemigrations <app_name>
之后,我得到以下错误:
python manage.py makemigrations main
SystemCheckError: System check identified some issues:
ERRORS:
auth.Group_permissions: (fields.E336) The models is used as an intermediate models by '<django.db.models.fields.related.ManyToManyField: permissions>', but it does not have a foreign key to 'Group' or 'Permission'.
auth.User_groups: (fields.E336) The models is used as an intermediate models by '<django.db.models.fields.related.ManyToManyField: groups>', but it does not have a foreign key to 'User' or 'Group'.
auth.User_user_permissions: (fields.E336) The models is used as an intermediate models by '<django.db.models.fields.related.ManyToManyField: user_permissions>', but it does not have a foreign key to 'User' or 'Permission'.
contenttypes.ContentType: (models.E012) 'unique_together' refers to the nonexistent field 'models'.
我真的不明白他们的意思(至少他们看起来很相似)。在我的模型中,实际上有很多关系,我从来没有修改过错误消息(User,Group)中列出的任何类。你知道吗
我不知道我的模型代码是否与此相关。但我对我的项目结构持怀疑态度;我已经离开了型号.py文件为空,并创建了一个新目录“models”,其中包含我的所有模型文件。所以:
<m_app>
├── migrations
│
├── sumbmodels
│ └── __init__.py <--- imports modelA, modelB, etc
| └── modelA.py
| └── modelB.py
| └── ...
|
├── static
│ └── <my_app>
|
├── templates
│ └── <my_app>
|
├── tests
│ └── __init__.py
| └── testA.py
| └── testB.py
| └── ...
│
└── models.py <--- from .submodels import *
│
└── ...
我很抱歉,如果这是没有太多的信息,但鉴于这个错误,我不知道在哪里看。你知道吗
首先,我建议坚持Django基础设计-将所有模型保持在
models.py
中。你知道吗当模型数量变大时,您可以考虑将这样大的应用程序分成几个较小的应用程序,每个应用程序只负责其功能。django项目可能包含多个应用程序。你知道吗
如果你想在多个文件中有模型-检查[这个答案] (Split models.py into several files)。你知道吗
相关问题 更多 >
编程相关推荐