Django-allauth: django_site relation does not exist error when when running tests

Created on 31 Aug 2017  路  8Comments  路  Source: pennersr/django-allauth

I'm running trying to run my tests, but I keep getting the following errors.

errors

Loading : /Users/guyjacks/projects/one_raft_first_site/.env
The .env file has been loaded. See base.py for more information
============================= test session starts ==============================
platform darwin -- Python 3.5.2, pytest-3.0.7, py-1.4.33, pluggy-0.4.0
Django settings: config.settings.test (from ini file)
rootdir: /Users/guyjacks/projects/one_raft_first_site, inifile: pytest.ini
plugins: django-3.1.2, mock-1.6.2, sugar-0.8.0
collected 2 items

one_raft_first_site/impact/tests/test_action_model_manager.py EF

==================================== ERRORS ====================================
____________________ ERROR at setup of test_filter_by_month ____________________

self = <django.db.backends.utils.CursorWrapper object at 0x10a5bc8d0>
sql = 'ALTER TABLE "socialaccount_socialapp_sites" ADD CONSTRAINT "socialaccount_socialapp_site_site_id_2579dee5_fk_django_site_id" FOREIGN KEY ("site_id") REFERENCES "django_site" ("id") DEFERRABLE INITIALLY DEFERRED'
params = None

    def execute(self, sql, params=None):
        self.db.validate_no_broken_transaction()
        with self.db.wrap_database_errors:
            if params is None:
>               return self.cursor.execute(sql)
E               psycopg2.ProgrammingError: relation "django_site" does not exist

../../.pyenv/versions/3.5.2/envs/orfs/lib/python3.5/site-packages/django/db/backends/utils.py:62: ProgrammingError

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

request = <SubRequest '_django_db_marker' for <Function 'test_filter_by_month'>>

    @pytest.fixture(autouse=True)
    def _django_db_marker(request):
        """Implement the django_db marker, internal to pytest-django.

        This will dynamically request the ``db`` or ``transactional_db``
        fixtures as required by the django_db marker.
        """
        marker = request.keywords.get('django_db', None)
        if marker:
            validate_django_db(marker)
            if marker.transaction:
                getfixturevalue(request, 'transactional_db')
            else:
>               getfixturevalue(request, 'db')

../../.pyenv/versions/3.5.2/envs/orfs/lib/python3.5/site-packages/pytest_django/plugin.py:376: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
../../.pyenv/versions/3.5.2/envs/orfs/lib/python3.5/site-packages/pytest_django/pytest_compat.py:3: in getfixturevalue
    return request.getfixturevalue(value)
../../.pyenv/versions/3.5.2/envs/orfs/lib/python3.5/site-packages/pytest_django/fixtures.py:97: in django_db_setup
    **setup_databases_args
../../.pyenv/versions/3.5.2/envs/orfs/lib/python3.5/site-packages/django/test/runner.py:743: in setup_databases
    serialize=connection.settings_dict.get("TEST", {}).get("SERIALIZE", True),
../../.pyenv/versions/3.5.2/envs/orfs/lib/python3.5/site-packages/django/db/backends/base/creation.py:70: in create_test_db
    run_syncdb=True,
../../.pyenv/versions/3.5.2/envs/orfs/lib/python3.5/site-packages/django/core/management/__init__.py:130: in call_command
    return command.execute(*args, **defaults)
../../.pyenv/versions/3.5.2/envs/orfs/lib/python3.5/site-packages/django/core/management/base.py:345: in execute
    output = self.handle(*args, **options)
../../.pyenv/versions/3.5.2/envs/orfs/lib/python3.5/site-packages/django/core/management/commands/migrate.py:173: in handle
    self.sync_apps(connection, executor.loader.unmigrated_apps)
../../.pyenv/versions/3.5.2/envs/orfs/lib/python3.5/site-packages/django/core/management/commands/migrate.py:316: in sync_apps
    cursor.execute(statement)
../../.pyenv/versions/3.5.2/envs/orfs/lib/python3.5/site-packages/django/db/backends/utils.py:64: in execute
    return self.cursor.execute(sql, params)
../../.pyenv/versions/3.5.2/envs/orfs/lib/python3.5/site-packages/django/db/utils.py:94: in __exit__
    six.reraise(dj_exc_type, dj_exc_value, traceback)
../../.pyenv/versions/3.5.2/envs/orfs/lib/python3.5/site-packages/django/utils/six.py:685: in reraise
    raise value.with_traceback(tb)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <django.db.backends.utils.CursorWrapper object at 0x10a5bc8d0>
sql = 'ALTER TABLE "socialaccount_socialapp_sites" ADD CONSTRAINT "socialaccount_socialapp_site_site_id_2579dee5_fk_django_site_id" FOREIGN KEY ("site_id") REFERENCES "django_site" ("id") DEFERRABLE INITIALLY DEFERRED'
params = None

    def execute(self, sql, params=None):
        self.db.validate_no_broken_transaction()
        with self.db.wrap_database_errors:
            if params is None:
>               return self.cursor.execute(sql)
E               django.db.utils.ProgrammingError: relation "django_site" does not exist

../../.pyenv/versions/3.5.2/envs/orfs/lib/python3.5/site-packages/django/db/backends/utils.py:62: ProgrammingError
=================================== FAILURES ===================================
__________________ test_filter_by_this_month_for_organization __________________

    def test_filter_by_this_month_for_organization():
>       assert False
E       assert False

one_raft_first_site/impact/tests/test_action_model_manager.py:24: AssertionError
====================== 1 failed, 1 error in 0.62 seconds =======================

settings.py

...

# APP CONFIGURATION
# ------------------------------------------------------------------------------
DJANGO_APPS = [
    # Default Django apps:
    'django.contrib.auth',
    'django.contrib.sites',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',

    # Useful template tags:
    # 'django.contrib.humanize',

    # Admin
    'django.contrib.admin',
]
THIRD_PARTY_APPS = [
    'crispy_forms',  # Form layouts
    'tinymce',
    'allauth',  # registration
    'allauth.account',  # registration
    'allauth.socialaccount',  # registration
    #'allauth.socialaccount.providers.facebook',
]

# Apps specific for this project go here.
LOCAL_APPS = [
    # custom users app
    'one_raft_first_site.users.apps.UsersConfig',
    # Your stuff: custom apps go here
    'one_raft_first_site.impact',
    'one_raft_first_site.locations',
    'one_raft_first_site.organizations',
    'one_raft_first_site.cart',
]

# See: https://docs.djangoproject.com/en/dev/ref/settings/#installed-apps
INSTALLED_APPS = DJANGO_APPS + THIRD_PARTY_APPS + LOCAL_APPS

MIDDLEWARE = [
    'django.middleware.security.SecurityMiddleware',
    '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',
]

MIGRATION_MODULES = {
    'sites': 'one_raft_first_site.contrib.sites.migrations'
}

...

AUTHENTICATION_BACKENDS = [
    'django.contrib.auth.backends.ModelBackend',
    'allauth.account.auth_backends.AuthenticationBackend',
]

# Replace username with email
ACCOUNT_AUTHENTICATION_METHOD = 'email'
ACCOUNT_EMAIL_REQUIRED = True
ACCOUNT_EMAIL_VERIFICATION = 'mandatory'
ACCOUNT_USER_MODEL_USERNAME_FIELD = None
ACCOUNT_USERNAME_REQUIRED = False

ACCOUNT_SIGNUP_FORM_CLASS = 'one_raft_first_site.users.forms.SignupForm'
ACCOUNT_ALLOW_REGISTRATION = env.bool('DJANGO_ACCOUNT_ALLOW_REGISTRATION', True)
ACCOUNT_ADAPTER = 'one_raft_first_site.users.adapters.AccountAdapter'

SOCIALACCOUNT_ADAPTER = 'one_raft_first_site.users.adapters.SocialAccountAdapter'

...

Most helpful comment

I have the same issue,
Fixed with downgrade to:
pip install django-rest-auth==0.9.2

But i need to be on the 0.9.3 latest version , any suggestion?

Update:

Fixed by adding:

INSTALLED_APPS  = (
...
'allauth.socialaccount',
...
)

All 8 comments

Have you set SITE_ID = 1?

I have the same issue,
Fixed with downgrade to:
pip install django-rest-auth==0.9.2

But i need to be on the 0.9.3 latest version , any suggestion?

Update:

Fixed by adding:

INSTALLED_APPS  = (
...
'allauth.socialaccount',
...
)

@omidraha thank you so much for the update! This is the only thing worked for my case of "relation "django_site" does not exist" bug.

I have the same issue,
Fixed with downgrade to:
pip install django-rest-auth==0.9.2

But i need to be on the 0.9.3 latest version , any suggestion?

Update:

Fixed by adding:

INSTALLED_APPS  = (
...
'allauth.socialaccount',
...
)

@omidraha Thanks Man this worked really well

Guys, this is still the issue (at least for me).

his is still the issue for me too.

Still the same issue.. tried many solution, no one worked

Closing -- https://django-allauth.readthedocs.io/en/latest/faq.html#why-did-you-just-close-my-issue

Was this page helpful?
0 / 5 - 0 ratings