我试过所有发现的东西:
Can stale content types be automatically deleted in Django?
Deleting unused Models, stale content types prompt
InvalidBasesError: Cannot resolve bases for [<ModelState: 'users.GroupProxy'>]
Django Wagtail CMS migrate: Cannot resolve bases for [<ModelState: 'app.CustomPage'>
所以我的问题是:我有:
Planche
的ComicBook
Bande
的Planche
Vignette
的Bande
我需要在多对多的表之间添加“importance
”字段,以便能够定制某种关系。所以我创造了
ComicBookPlanche
,它是带有字段importance
的多对多表PlancheBande
,它是带有字段importance
的多对多表在我决定将ComicBook
重命名为Book
之前,一切都很顺利。从现在起,我总是收到消息django.db.migrations.state.InvalidBasesError: Cannot resolve bases for...
我甚至试图删除所有的表和迁移文件夹。。。我试图对我的申请进行评论->很好然后取消评论,但仍然:
django.db.migrations.state.InvalidBasesError:
Cannot resolve bases for
[<ModelState: 'main.TexteLongTextesThrough'>,
<ModelState: 'main.TexteCourtTextesThrough'>,
<ModelState: 'main.VignetteBullesThrough'>,
<ModelState: 'main.LivrePlanchesThrough'>]
我快疯了。所以我是这么做的:
makemigrations
然后migrate
->;验证、管理、会话、站点创建没有问题models.py
而不使用admin.py
。在makemigrations
->;完美:
然后migrate
->;完美:
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
然后复制/粘贴我的admin.py
,然后makemigrations
->;完美:
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
它总是问我这个问题,不管我回答“是”还是“否”:
>>> migrate
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:
No migrations to apply.
The following content types are stale and need to be deleted:
main | textelong_textes
main | textecourt_textes
main | livre_planches
main | vignette_bulles
Any objects related to these content types by a foreign key will also
be deleted. Are you sure you want to delete these content types?
If you're unsure, answer 'no'.
Type 'yes' to continue, or 'no' to cancel: yes
Process finished with exit code 0
我该怎么做才能让他不再问,问题出在哪里?在
这里有几点:看起来您在一批迁移中创建了模型,然后在第二批迁移中创建了through表。这是错误的,您应该在主模型的同时编写和迁移through表。在
在最后一个例子中发生的事情是,当您第一次创建模型时,django创建了自己的标准穿透表,然后您添加了custom through表,所以django要求您删除原始的(旧的)表。在
按照您编写所有内容的方式,您似乎将through表的模型定义放在
admin.py
中?你为什么要那样做?它们应该在models.py
中,就在它们“连接”的模型旁边。在另外,您不应该使用
Proxy
模型,并且没有实际的源代码,这很可能是问题的根本原因。如果您所要做的只是在through关系上有一个额外的字段,那么您应该遵循以下模式:https://docs.djangoproject.com/en/1.8/topics/db/models/#extra-fields-on-many-to-many-relationships相关问题 更多 >
编程相关推荐