重新排序初始迁移操作

2024-09-24 04:24:46 发布

您现在位置:Python中文网/ 问答频道 /正文

每次尝试migrate我的初始迁移,就在makemigrations之后,我都会遇到如下错误:

django.db.migrations.exceptions.InvalidBasesError: Cannot resolve bases for [<ModelState: 'Project.Class'>]
This can happen if you are inheriting models from an app with migrations (e.g. contrib.auth)

我认为发生这种情况的原因是0001_initial.py迁移中模型operations的顺序不正确。具有从其他类继承的类的操作被添加到其父类的前面。在我对操作重新排序之后,它工作:Process finished with exit code 0。酷!但是,如果每次都不这样做,我如何使makemigrations工作呢?你知道吗

谢谢!你知道吗

另外,我尝试在模型的__init__.py中重新排序模型的导入顺序,但没有成功。你知道吗


Tags: djangopy模型db排序顺序migrations错误