Python 为什么Django不断询问内容类型过时,需要删除
我尝试了所有发现的东西: 所以我的问题是:我有:Python 为什么Django不断询问内容类型过时,需要删除,python,django,django-models,django-modeladmin,django-model-utils,Python,Django,Django Models,Django Modeladmin,Django Model Utils,我尝试了所有发现的东西: 所以我的问题是:我有: 具有多对多平面图的漫画书 具有多对多波段的平面图 具有多对多渐晕图的波段 。。。还有三个更深的层次(这并不重要,始终是相同的原则) 我需要在多对多表之间添加“重要性”字段,以便能够建立自定义的关系排序。所以我创造了 一个ComicBookPlanche表,它是具有字段重要性的多对多表 一个plancheband即具有字段重要性的多对多表 在我决定将ComicBook重命名为Book之前,一切都很顺利。从现在起,我总是收到这样一条
- 具有多对多
平面图的
漫画书
- 具有多对多
波段的
平面图
- 具有多对多
渐晕图的
波段
- 。。。还有三个更深的层次(这并不重要,始终是相同的原则)
重要性
”字段,以便能够建立自定义的关系排序。所以我创造了
- 一个
表,它是具有字段ComicBookPlanche
重要性的多对多表
- 一个
即具有字段plancheband
重要性的多对多表
ComicBook
重命名为Book
之前,一切都很顺利。从现在起,我总是收到这样一条消息:django.db.migrations.state.InvalidBasesError:无法解析…
我甚至试着删除所有的表和迁移文件夹,没有任何改变。。。我试图评论我的应用程序->很好,然后取消评论,但仍然:
django.db.migrations.state.InvalidBasesError:
Cannot resolve bases for
[<ModelState: 'main.TexteLongTextesThrough'>,
<ModelState: 'main.TexteCourtTextesThrough'>,
<ModelState: 'main.VignetteBullesThrough'>,
<ModelState: 'main.LivrePlanchesThrough'>]
然后迁移
->完美:
Migrations for 'main':
0001_initial.py:
- Create model Bande
- Create model BandeVignette
- Create model Bulle
- Create model ContenuCourt
- Create model ContenuLong
- Create model Langue
- Create model Livre
- Create model Personne
- Create model Planche
- Create model PlancheBande
- Create model TexteCourt
- Create model TexteLong
- Create model Vignette
- Add field description to planche
- Add field planches to livre
Operations to perform:
Synchronize unmigrated apps: staticfiles, messages
Apply all migrations: sessions, admin, sites, auth, contenttypes, main
Synchronizing apps without migrations:
Creating tables...
Running deferred SQL...
Installing custom SQL...
Running migrations:
Rendering model states... DONE
Applying main.0001_initial... OK
Process finished with exit code 0
Migrations for 'main':
0002_livreplanchesthrough_textecourttextesthrough_textelongtextesthrough_vignettebullesthrough.py:
- Create proxy model LivrePlanchesThrough
- Create proxy model TexteCourtTextesThrough
- Create proxy model TexteLongTextesThrough
- Create proxy model VignetteBullesThrough
Process finished with exit code 0
然后复制/粘贴我的admin.py
然后makemigrations
->完美:
Migrations for 'main':
0001_initial.py:
- Create model Bande
- Create model BandeVignette
- Create model Bulle
- Create model ContenuCourt
- Create model ContenuLong
- Create model Langue
- Create model Livre
- Create model Personne
- Create model Planche
- Create model PlancheBande
- Create model TexteCourt
- Create model TexteLong
- Create model Vignette
- Add field description to planche
- Add field planches to livre
Operations to perform:
Synchronize unmigrated apps: staticfiles, messages
Apply all migrations: sessions, admin, sites, auth, contenttypes, main
Synchronizing apps without migrations:
Creating tables...
Running deferred SQL...
Installing custom SQL...
Running migrations:
Rendering model states... DONE
Applying main.0001_initial... OK
Process finished with exit code 0
Migrations for 'main':
0002_livreplanchesthrough_textecourttextesthrough_textelongtextesthrough_vignettebullesthrough.py:
- Create proxy model LivrePlanchesThrough
- Create proxy model TexteCourtTextesThrough
- Create proxy model TexteLongTextesThrough
- Create proxy model VignetteBullesThrough
Process finished with exit code 0
然后每次我尝试migrate
时,它总是问我这个问题,不管我回答“是”还是“否”:
我该怎么做才能让他不再问,问题出在哪里?这里有几件事:看起来您在一批迁移中创建了模型,然后在第二批迁移中创建了贯穿表。这是错误的,您应该在主模型的同时编写和迁移贯穿表 上一个示例中发生的情况是,当您第一次创建模型时,django创建了自己的标准直通表,然后添加了自定义直通表,因此django要求您删除原始(旧)直通表 按照您编写所有内容的方式,您似乎将贯穿表的模型定义放在了
admin.py
中?你为什么要那样做?它们应该位于它们“连接”的模型旁边的models.py
另外,您不应该使用
代理
模型,并且没有实际的源代码,这很可能是问题的根本原因。如果您只是想在直通关系上增加一个字段,那么您应该遵循以下模式:我认为您是对的。我发现问题在于:(1)我可以声明我的模型,如Bande
、Vignette
和BandeVignette
,而不明确声明BandeVignette
是代理(通过class='BandeVignette'
),然后当我复制/粘贴admin.py
,django kinddof“发现”我有一个代理表,并试图创建它们。因此,这要么很奇怪,要么就是一个问题:如果在models.py
中没有正确声明Vignette.bulles.through
,那么您应该无法在admin.py
中声明Vignette.bulles.through
,但您似乎可以这样做。这就造成了问题。所以我检查你的答案是否正确,因为你提供了足够的建议,让新来者走上正确的道路。非常感谢你