我已经尝试了所有发现的事情:
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'>
所以这就是我的问题:我有:
ComicBook
,其中包含多对多Planche
Planche
,其中包含多对多Bande
Bande
,其中包含多对多Vignette
我需要在多对多表之间添加&#34; importance
&#34;字段能够自定义关系的种类。因此我创造了
ComicBookPlanche
,即带有字段importance
PlancheBande
,即带有字段importance
在我决定将ComicBook
重命名为Book
之前,一切正常。从现在开始,我总是收到消息django.db.migrations.state.InvalidBasesError: Cannot resolve bases for...
我甚至尝试删除所有表格 和 迁移文件夹,没有任何更改......我试图评论我的应用程序 - &gt;伟大的,然后取消评论,仍然:
django.db.migrations.state.InvalidBasesError:
Cannot resolve bases for
[<ModelState: 'main.TexteLongTextesThrough'>,
<ModelState: 'main.TexteCourtTextesThrough'>,
<ModelState: 'main.VignetteBullesThrough'>,
<ModelState: 'main.LivrePlanchesThrough'>]
我生气了。所以这就是我所做的:
makemigrations
然后migrate
- &gt;认证,管理员,会话,网站创建没有问题models.py
,不用 admin.py
。 makemigrations
- &gt;完美:
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
然后migrate
- &gt;完美:
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
- &gt;完美:
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
时,它都会一直问我这个问题,无论我是否回答过,#34;是&#34;或&#34;不&#34;:
>>> 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
我该怎么办才能让他停止询问,问题是什么?
答案 0 :(得分:1)
这里有一些事情:看起来您在一批迁移中创建了模型,然后在第二批迁移中创建了直通表。这是错误的,您应该在主模型的同时编写和迁移直通表。
最后一个例子中发生的事情是,当你第一次创建模型时,django通过表创建了它自己的标准,然后你去了并通过表添加了自定义,所以django要求你删除原来的(旧的)。
您表达了所有内容的方式,看起来您在models.py
中放置了直通表的模型定义?为什么要这么做?它们应位于Proxy
旁边的模型旁边&#34;连接&#34;。
此外,您不应该使用class Person {
private var name: String
init(name: String) {
self.name = name
}
func setName(name: String) {
self.name = name
}
func getName() -> String {
return name
}
}
模型,并且没有实际的源代码,这可能是问题的根本原因。如果您尝试做的只是在通过关系上有一个额外的字段,那么您应该遵循以下模式:https://docs.djangoproject.com/en/1.8/topics/db/models/#extra-fields-on-many-to-many-relationships