Django Wagtail CMS 迁移:无法解析 [<ModelState: 'app.CustomPage'> 的基础

Django Wagtail CMS migrate: Cannot resolve bases for [<ModelState: 'app.CustomPage'>

我在迁移基于 Wagtail CMS 的简单应用程序时遇到问题。

运行ing python manage.py migrate 之后的回溯:

  Rendering model states...Traceback (most recent call last):
  File "manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/home/yanik/oasis/oasis/venv/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 338, in execute_from_command_line
    utility.execute()
  File "/home/yanik/oasis/oasis/venv/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 330, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/home/yanik/oasis/oasis/venv/local/lib/python2.7/site-packages/django/core/management/base.py", line 393, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/home/yanik/oasis/oasis/venv/local/lib/python2.7/site-packages/django/core/management/base.py", line 444, in execute
    output = self.handle(*args, **options)
  File "/home/yanik/oasis/oasis/venv/local/lib/python2.7/site-packages/django/core/management/commands/migrate.py", line 222, in handle
    executor.migrate(targets, plan, fake=fake, fake_initial=fake_initial)
  File "/home/yanik/oasis/oasis/venv/local/lib/python2.7/site-packages/django/db/migrations/executor.py", line 100, in migrate
    state.apps  # Render all real_apps -- performance critical
  File "/home/yanik/oasis/oasis/venv/local/lib/python2.7/site-packages/django/utils/functional.py", line 60, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
  File "/home/yanik/oasis/oasis/venv/local/lib/python2.7/site-packages/django/db/migrations/state.py", line 166, in apps
    return StateApps(self.real_apps, self.models)
  File "/home/yanik/oasis/oasis/venv/local/lib/python2.7/site-packages/django/db/migrations/state.py", line 232, in __init__
    self.render_multiple(list(models.values()) + self.real_models)
  File "/home/yanik/oasis/oasis/venv/local/lib/python2.7/site-packages/django/db/migrations/state.py", line 270, in render_multiple
    "for more" % (new_unrendered_models, get_docs_version())
django.db.migrations.state.InvalidBasesError: Cannot resolve bases for [<ModelState: 'common.HomePage'>, <ModelState: 'news.NewsPage'>]
This can happen if you are inheriting models from an app with migrations (e.g. contrib.auth)
 in an app with no migrations; see https://docs.djangoproject.com/en/1.8/topics/migrations/#dependencies for more

我的应用程序如下所示:

DJANGO_APPS = (
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
)

THIRD_PARTY_APPS = (
    'django_browserid', # Load after auth
    # Wagtail CMS
    'taggit',
    'compressor',
    'modelcluster',

    'wagtail.wagtailcore',
    'wagtail.wagtailadmin',
    'wagtail.wagtailsearch',
    'wagtail.wagtailimages',
    'wagtail.wagtaildocs',
    'wagtail.wagtailsnippets',
    'wagtail.wagtailusers',
    'wagtail.wagtailsites',
    'wagtail.wagtailembeds',
    'wagtail.wagtailredirects',
    'wagtail.wagtailforms',

    'wagtailforums',
)

PROJECT_APPS = (
    'common',
    'search',
    'ckanwrap',
    'news',
    #'forum'
)

INSTALLED_APPS = DJANGO_APPS + THIRD_PARTY_APPS + PROJECT_APPS

我可以使初始迁移工作的唯一方法:从 INSTALLED_APPS 中删除 PROJECT_APPS,迁移。然后添加 PROJECT_APPS 并再次迁移。

但我还有许多其他问题:无法 运行 测试,导致出现同样的错误。另外,如果我修改我的模型和 运行 python manage.py makemigrations 我有 Nothing to migrate 但我改变了我的模型!

有什么建议吗?

谢谢。

正如@knbk 建议的那样,我应该专门为每个应用程序创建初始迁移!由于 makemigrations 不会自动执行此操作。

在我的例子中是:

python manage.py makemigrations common

python manage.py makemigrations news