Home » Python » python – ValueError: Related model 'wagtailimages.Image' cannot be resolved-Exceptionshub

python – ValueError: Related model 'wagtailimages.Image' cannot be resolved-Exceptionshub

Posted by: admin February 24, 2020 Leave a comment

Questions:

I just started to attempt writing tests for a blog written based on Django and Wagtail CMS. When I run python manage.py test, this is the result that I get from the terminal.

Creating test database for alias 'default'...
Traceback (most recent call last):
  File "manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/home/alvindera/.local/lib/python3.6/site-packages/django/core/management/__init__.py", line 381, in execute_from_command_line
    utility.execute()
  File "/home/alvindera/.local/lib/python3.6/site-packages/django/core/management/__init__.py", line 375, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/home/alvindera/.local/lib/python3.6/site-packages/django/core/management/commands/test.py", line 23, in run_from_argv
    super().run_from_argv(argv)
  File "/home/alvindera/.local/lib/python3.6/site-packages/django/core/management/base.py", line 323, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/home/alvindera/.local/lib/python3.6/site-packages/django/core/management/base.py", line 364, in execute
    output = self.handle(*args, **options)
  File "/home/alvindera/.local/lib/python3.6/site-packages/django/core/management/commands/test.py", line 53, in handle
    failures = test_runner.run_tests(test_labels)
  File "/home/alvindera/.local/lib/python3.6/site-packages/django/test/runner.py", line 629, in run_tests
    old_config = self.setup_databases(aliases=databases)
  File "/home/alvindera/.local/lib/python3.6/site-packages/django/test/runner.py", line 554, in setup_databases
    self.parallel, **kwargs
  File "/home/alvindera/.local/lib/python3.6/site-packages/django/test/utils.py", line 174, in setup_databases
    serialize=connection.settings_dict.get('TEST', {}).get('SERIALIZE', True),
  File "/home/alvindera/.local/lib/python3.6/site-packages/django/db/backends/base/creation.py", line 72, in create_test_db
    run_syncdb=True,
  File "/home/alvindera/.local/lib/python3.6/site-packages/django/core/management/__init__.py", line 148, in call_command
    return command.execute(*args, **defaults)
  File "/home/alvindera/.local/lib/python3.6/site-packages/django/core/management/base.py", line 364, in execute
    output = self.handle(*args, **options)
  File "/home/alvindera/.local/lib/python3.6/site-packages/django/core/management/base.py", line 83, in wrapped
    res = handle_func(*args, **kwargs)
  File "/home/alvindera/.local/lib/python3.6/site-packages/django/core/management/commands/migrate.py", line 234, in handle
    fake_initial=fake_initial,
  File "/home/alvindera/.local/lib/python3.6/site-packages/django/db/migrations/executor.py", line 117, in migrate
    state = self._migrate_all_forwards(state, plan, full_plan, fake=fake, fake_initial=fake_initial)
  File "/home/alvindera/.local/lib/python3.6/site-packages/django/db/migrations/executor.py", line 147, in _migrate_all_forwards
    state = self.apply_migration(state, migration, fake=fake, fake_initial=fake_initial)
  File "/home/alvindera/.local/lib/python3.6/site-packages/django/db/migrations/executor.py", line 245, in apply_migration
    state = migration.apply(state, schema_editor)
  File "/home/alvindera/.local/lib/python3.6/site-packages/django/db/migrations/migration.py", line 124, in apply
    operation.database_forwards(self.app_label, schema_editor, old_state, project_state)
  File "/home/alvindera/.local/lib/python3.6/site-packages/django/db/migrations/operations/fields.py", line 249, in database_forwards
    schema_editor.alter_field(from_model, from_field, to_field)
  File "/home/alvindera/.local/lib/python3.6/site-packages/django/db/backends/sqlite3/schema.py", line 137, in alter_field
    super().alter_field(model, old_field, new_field, strict=strict)
  File "/home/alvindera/.local/lib/python3.6/site-packages/django/db/backends/base/schema.py", line 507, in alter_field
    new_db_params = new_field.db_parameters(connection=self.connection)
  File "/home/alvindera/.local/lib/python3.6/site-packages/django/db/models/fields/related.py", line 966, in db_parameters
    return {"type": self.db_type(connection), "check": self.db_check(connection)}
  File "/home/alvindera/.local/lib/python3.6/site-packages/django/db/models/fields/related.py", line 963, in db_type
    return self.target_field.rel_db_type(connection=connection)
  File "/home/alvindera/.local/lib/python3.6/site-packages/django/db/models/fields/related.py", line 878, in target_field
    return self.foreign_related_fields[0]
  File "/home/alvindera/.local/lib/python3.6/site-packages/django/db/models/fields/related.py", line 632, in foreign_related_fields
    return tuple(rhs_field for lhs_field, rhs_field in self.related_fields if rhs_field)
  File "/home/alvindera/.local/lib/python3.6/site-packages/django/db/models/fields/related.py", line 619, in related_fields
    self._related_fields = self.resolve_related_fields()
  File "/home/alvindera/.local/lib/python3.6/site-packages/django/db/models/fields/related.py", line 604, in resolve_related_fields
    raise ValueError('Related model %r cannot be resolved' % self.remote_field.model)
ValueError: Related model 'wagtailimages.Image' cannot be resolved

I have absolutely no idea what is wrong or what to do since I do not know exactly what the error is pointing at. Thanks in anticipation.

Here is my settings.py file:

"""
Django settings for ixorabloom_blog project.

Generated by 'django-admin startproject' using Django 1.8.5.

For more information on this file, see
https://docs.djangoproject.com/en/1.8/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/1.8/ref/settings/
"""

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
import os

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

PROJECT_ROOT = os.path.abspath(os.path.dirname(__file__))

STATICFILES_DIRS = (
    os.path.join(PROJECT_ROOT, 'static'),  # just know that the value of this guy is where the working static files are
)

# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.8/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '

Answer:

Answer:

Answer:

Answer:

Answer:

Answer:

Answer:

Answer:

Answer:

Answer:

Answer:

Answer:

Answer:

Answer:

' # SECURITY WARNING: don't run with debug turned on in production! DEBUG = True ALLOWED_HOSTS = ['127.0.0.1', 'ixorabloom.pythonanywhere.com', ] # Application definition INSTALLED_APPS = ( 'wagtail.contrib.modeladmin', 'wagtail.contrib.forms', 'wagtail.contrib.redirects', 'wagtail.contrib.styleguide', 'wagtail.contrib.routable_page', 'wagtail.embeds', 'wagtail.sites', 'wagtail.users', 'wagtail.snippets', 'wagtail.documents', 'wagtail.images', 'wagtail.search', 'wagtail.admin', 'wagtail.core', 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', 'blog_index', 'blog', 'ixorabloom_users', 'django_unused_media', 'modelcluster', 'taggit', ) MIDDLEWARE = ( 'wagtail.core.middleware.SiteMiddleware', 'wagtail.contrib.redirects.middleware.RedirectMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.common.CommonMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.messages.middleware.MessageMiddleware', 'django.middleware.clickjacking.XFrameOptionsMiddleware', 'django.middleware.security.SecurityMiddleware', ) ROOT_URLCONF = 'ixorabloom_blog.urls' TEMPLATES = [ { 'BACKEND': 'django.template.backends.django.DjangoTemplates', 'DIRS': [os.path.join(BASE_DIR, 'blog_index/templates'), os.path.join(BASE_DIR, 'blog/templates'), os.path.join(BASE_DIR, 'ixorabloom_users/templates')], 'APP_DIRS': True, 'OPTIONS': { 'context_processors': [ 'django.template.context_processors.debug', 'django.template.context_processors.request', 'django.contrib.auth.context_processors.auth', 'django.contrib.messages.context_processors.messages', ], }, }, ] WSGI_APPLICATION = 'ixorabloom_blog.wsgi.application' # Database # https://docs.djangoproject.com/en/1.8/ref/settings/#databases DATABASES = { 'default': { 'ENGINE': 'django.db.backends.sqlite3', 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), } } WAGTAIL_SITE_NAME = 'Ixorabloom The Blog!' # Internationalization # https://docs.djangoproject.com/en/1.8/topics/i18n/ LANGUAGE_CODE = 'en-us' TIME_ZONE = 'Africa/Lagos' USE_I18N = True USE_L10N = True USE_TZ = True # Static files (CSS, JavaScript, Images) # https://docs.djangoproject.com/en/1.8/howto/static-files/ STATIC_URL = '/static/' STATIC_ROOT = os.path.join(BASE_DIR, 'ixorabloom_blog/new_static') MEDIA_URL = '/media/' MEDIA_ROOT = os.path.join(BASE_DIR, 'ixorabloom_blog/media') LOGIN_REDIRECT_URL = '/'

From the settings.py file (above), the project was started at Django version ‘1.8.5’. Now the project has been continually updated till it has reached Django version ‘2.2.2’.

The project started on it’s own (with vanilla Django) before Wagtail CMS was later added to it. This explains why there are no settings.base.py and settings.dev.py files. Only settings.py.

How to&Answers: