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

匿名 (未验证) 提交于 2019-12-03 09:05:37

问题:

I have problem migrate simple app, bases on Wagtail CMS.

Traceback after runing 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 

My Apps looks like this:

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 

The only way i can make initial migrations work: remove PROJECT_APPS from INSTALLED_APPS, migrate. And after add PROJECT_APPS and migrate again.

But I have many other problems: cant run tests, cause same error appeared. Also if i modify my models and run python manage.py makemigrations i have Nothing to migrate but i change my models!

Any suggestions?

Thank you.

回答1:

As @knbk suggested I should create initial migrations specifically for each app! Since makemigrations doesn't do it automatically.

In my case it was:

python manage.py makemigrations common  python manage.py makemigrations news 


标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!