Q:

DoesNotExist at /admin/login/ Site matching query does not exist in wagtail

I can't do anything in my admin panel because when i go to locahost:8000/admin it shows those errors:
DoesNotExist at /admin/login/
Site matching query does not exist.
Full traceback:
Environment:

Request Method: GET
Request URL: http://localhost:8000/admin/login/?next=/admin/

Django Version: 2.2.3
Python Version: 3.7.3
Installed Applications:
['home',
 'search',
 'blog',
 'wagtail.contrib.forms',
 'wagtail.contrib.redirects',
 'wagtail.embeds',
 'wagtail.sites',
 'wagtail.users',
 'wagtail.snippets',
 'wagtail.documents',
 'wagtail.images',
 'wagtail.search',
 'wagtail.admin',
 'wagtail.core',
 'modelcluster',
 'taggit',
 'django.contrib.admin',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'social_django',
 'django.contrib.sites',
 'django_comments_xtd',
 'django_comments']
Installed Middleware:
['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',
 'wagtail.core.middleware.SiteMiddleware',
 'wagtail.contrib.redirects.middleware.RedirectMiddleware',
 'social_django.middleware.SocialAuthExceptionMiddleware']

I also tried this question but it also throws errors:
Traceback:
    File "/home/fullnamedebian/.local/lib/python3.7/site-packages/django/contrib/sites/models.py" in _get_site_by_request
      39.                 SITE_CACHE[host] = self.get(domain__iexact=host)

    File "/home/fullnamedebian/.local/lib/python3.7/site-packages/django/db/models/manager.py" in manager_method
      82.                 return getattr(self.get_queryset(), name)(*args, **kwargs)

    File "/home/fullnamedebian/.local/lib/python3.7/site-packages/django/db/models/query.py" in get
      408.                 self.model._meta.object_name

    During handling of the above exception (Site matching query does not exist.), another exception occurred:

    File "/home/fullnamedebian/.local/lib/python3.7/site-packages/django/core/handlers/exception.py" in inner
      34.             response = get_response(request)

    File "/home/fullnamedebian/.local/lib/python3.7/site-packages/django/core/handlers/base.py" in _get_response
      115.                 response = self.process_exception_by_middleware(e, request)

    File "/home/fullnamedebian/.local/lib/python3.7/site-packages/django/core/handlers/base.py" in _get_response
      113.                 response = wrapped_callback(request, *callback_args, **callback_kwargs)

    File "/home/fullnamedebian/.local/lib/python3.7/site-packages/django/views/decorators/cache.py" in _wrapped_view_func
      44.         response = view_func(request, *args, **kwargs)

    File "/home/fullnamedebian/.local/lib/python3.7/site-packages/wagtail/admin/urls/__init__.py" in wrapper
      102.             return view_func(request, *args, **kwargs)

    File "/home/fullnamedebian/.local/lib/python3.7/site-packages/django/views/generic/base.py" in view
      71.             return self.dispatch(request, *args, **kwargs)

    File "/home/fullnamedebian/.local/lib/python3.7/site-packages/django/utils/decorators.py" in _wrapper
      45.         return bound_method(*args, **kwargs)

    File "/home/fullnamedebian/.local/lib/python3.7/site-packages/django/views/decorators/debug.py" in sensitive_post_parameters_wrapper
      76.             return view(request, *args, **kwargs)

    File "/home/fullnamedebian/.local/lib/python3.7/site-packages/django/utils/decorators.py" in _wrapper
      45.         return bound_method(*args, **kwargs)

    File "/home/fullnamedebian/.local/lib/python3.7/site-packages/django/utils/decorators.py" in _wrapped_view
      142.                     response = view_func(request, *args, **kwargs)

    File "/home/fullnamedebian/.local/lib/python3.7/site-packages/django/utils/decorators.py" in _wrapper
      45.         return bound_method(*args, **kwargs)

    File "/home/fullnamedebian/.local/lib/python3.7/site-packages/django/views/decorators/cache.py" in _wrapped_view_func
      44.         response = view_func(request, *args, **kwargs)

    File "/home/fullnamedebian/.local/lib/python3.7/site-packages/django/contrib/auth/views.py" in dispatch
      61.         return super().dispatch(request, *args, **kwargs)

    File "/home/fullnamedebian/.local/lib/python3.7/site-packages/django/views/generic/base.py" in dispatch
      97.         return handler(request, *args, **kwargs)

    File "/home/fullnamedebian/.local/lib/python3.7/site-packages/wagtail/admin/views/account.py" in get
      213.         return super().get(*args, **kwargs)

    File "/home/fullnamedebian/.local/lib/python3.7/site-packages/django/views/generic/edit.py" in get
      133.         return self.render_to_response(self.get_context_data())

    File "/home/fullnamedebian/.local/lib/python3.7/site-packages/wagtail/admin/views/account.py" in get_context_data
      219.         context = super().get_context_data(**kwargs)

    File "/home/fullnamedebian/.local/lib/python3.7/site-packages/django/contrib/auth/views.py" in get_context_data
      95.         current_site = get_current_site(self.request)

    File "/home/fullnamedebian/.local/lib/python3.7/site-packages/django/contrib/sites/shortcuts.py" in get_current_site
      13.         return Site.objects.get_current(request)

    File "/home/fullnamedebian/.local/lib/python3.7/site-packages/django/contrib/sites/models.py" in get_current
      60.             return self._get_site_by_request(request)

    File "/home/fullnamedebian/.local/lib/python3.7/site-packages/django/contrib/sites/models.py" in _get_site_by_request
      45.                 SITE_CACHE[domain] = self.get(domain__iexact=domain)

    File "/home/fullnamedebian/.local/lib/python3.7/site-packages/django/db/models/manager.py" in manager_method
      82.                 return getattr(self.get_queryset(), name)(*args, **kwargs)

    File "/home/fullnamedebian/.local/lib/python3.7/site-packages/django/db/models/query.py" in get
      408.                 self.model._meta.object_name

    Exception Type: DoesNotExist at /admin/login/
    Exception Value: Site matching query does not exist.

I tried [this question][1] but it throws:

Site.objects.create(name='example.com', domain='example.com')
Traceback (most recent call last):
  File "/home/fullnamedebian/.local/lib/python3.7/site-packages/django/db/backends/utils.py", line 84, in _execute
    return self.cursor.execute(sql, params)
  File "/home/fullnamedebian/.local/lib/python3.7/site-packages/django/db/backends/sqlite3/base.py", line 383, in execute
    return Database.Cursor.execute(self, query, params)
sqlite3.IntegrityError: UNIQUE constraint failed: django_site.domain

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/home/fullnamedebian/.local/lib/python3.7/site-packages/django/db/models/manager.py", line 82, in manager_method
    return getattr(self.get_queryset(), name)(*args, **kwargs)
  File "/home/fullnamedebian/.local/lib/python3.7/site-packages/django/db/models/query.py", line 422, in create
    obj.save(force_insert=True, using=self.db)
  File "/home/fullnamedebian/.local/lib/python3.7/site-packages/django/db/models/base.py", line 741, in save
    force_update=force_update, update_fields=update_fields)
  File "/home/fullnamedebian/.local/lib/python3.7/site-packages/django/db/models/base.py", line 779, in save_base
    force_update, using, update_fields,
  File "/home/fullnamedebian/.local/lib/python3.7/site-packages/django/db/models/base.py", line 870, in _save_table
    result = self._do_insert(cls._base_manager, using, fields, update_pk, raw)
  File "/home/fullnamedebian/.local/lib/python3.7/site-packages/django/db/models/base.py", line 908, in _do_insert
    using=using, raw=raw)
  File "/home/fullnamedebian/.local/lib/python3.7/site-packages/django/db/models/manager.py", line 82, in manager_method
    return getattr(self.get_queryset(), name)(*args, **kwargs)
  File "/home/fullnamedebian/.local/lib/python3.7/site-packages/django/db/models/query.py", line 1186, in _insert
    return query.get_compiler(using=using).execute_sql(return_id)
  File "/home/fullnamedebian/.local/lib/python3.7/site-packages/django/db/models/sql/compiler.py", line 1335, in execute_sql
    cursor.execute(sql, params)
  File "/home/fullnamedebian/.local/lib/python3.7/site-packages/django/db/backends/utils.py", line 99, in execute
    return super().execute(sql, params)
  File "/home/fullnamedebian/.local/lib/python3.7/site-packages/django/db/backends/utils.py", line 67, in execute
    return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
  File "/home/fullnamedebian/.local/lib/python3.7/site-packages/django/db/backends/utils.py", line 76, in _execute_with_wrappers
    return executor(sql, params, many, context)
  File "/home/fullnamedebian/.local/lib/python3.7/site-packages/django/db/backends/utils.py", line 84, in _execute
    return self.cursor.execute(sql, params)
  File "/home/fullnamedebian/.local/lib/python3.7/site-packages/django/db/utils.py", line 89, in __exit__
    raise dj_exc_value.with_traceback(traceback) from exc_value
  File "/home/fullnamedebian/.local/lib/python3.7/site-packages/django/db/backends/utils.py", line 84, in _execute
    return self.cursor.execute(sql, params)
  File "/home/fullnamedebian/.local/lib/python3.7/site-packages/django/db/backends/sqlite3/base.py", line 383, in execute
    return Database.Cursor.execute(self, query, params)
django.db.utils.IntegrityError: UNIQUE constraint failed: django_site.domain

In last time, i was switching to development version of wagtail, but then i backed to normal, stable version by just installing wagtail with pip. I don't remember if I was doing some weird things in last time that could cause this bug. Thank you.

A:

Simple mistake - I accidently added 'django.contrib.sites' to installed app. Just remove it and it works as excepted.

