test app results in django.db.utils.OperationalError: no such table: django_site

Upgraded Django 2.2LTS to Django 3.2.9 along with a bunch of python packages. I expected problems but not this problem.

$ test app.tests.test_models
Creating test database for alias ‘default’…
sqlite3.OperationalError: no such table: django_site

I just assumed I forgot to do migrations

$ makemigrations
No changes detected
$ migrate
Operations to perform:
Apply all migrations: account, admin, auth, contenttypes, app, sessions, sites, socialaccount
Running migrations:
No migrations to apply.

The table is there

$ sqlite3 db.sqlite3
sqlite> .tables django_site

django_site database schema look correct

Basic django User model tests

from django.contrib.auth import get_user_model
from django.test import TestCase

User = get_user_model()

class UserTestCase(TestCase):
    def test_user_username(self):
        user = User.objects.get(id=1)
        self.assertTrue(len(user.username) > 0)

    def test_user_email(self):
        user = User.objects.get(id=1)

    def test_user_permissons(self):
        user = User.objects.get(id=1)

Same problem

$ test judgingportal.tests.test_tests.UserTestCase
django.db.utils.OperationalError: no such table: django_site

Any help would be appreciated. Thank you.

Try adding the -v 3 parameter to your test command. It’ll show you what apps are being included in the test run.

The first thought that comes to my mind is that you’ve got some table / model / view that is accessing the Site model, but you don’t have the Sites package currently in your INSTALLED_APPS list. If you had the Sites framework installed at one point, that table would have been created. If you’ve removed that from INSTALLED_APPS, the table would still be there, but I wouldn’t expect it to be copied by the test runner to your test database.

In general, I’d be taking a hard look at my models and settings to ensure that everything matched-up.

django.contrib.sites is in INSTALLED_APPS and git tells me it’s been there since the beginning.


I do not find a migration for the Site model in project migrations. I only find the migration in the package at django/contrib/sites/migrations/ but I’ll run with -v 3 and see what it reports.

Thank you for advise.