Opened 8 years ago

Closed 8 years ago

#16515 closed Bug (duplicate)

Testing with multiple databases assumes sites app installed on all of them

Reported by: Ryan Fugger Owned by: nobody
Component: Testing framework Version: master
Severity: Normal Keywords:
Cc: arv@… Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


I am trying to run tests on a project with two databases. One of them has all the default django apps installed on them, including sites. The other has some of my own apps. When creating the test databases, I get the following error:

  File "/home/ryan/projects/villages/django/db/backends/", line 256, in create_test_db
    if Site is not None and Site.objects.using(self.connection.alias).count() == 1:
  File "/home/ryan/projects/villages/django/db/models/", line 331, in count
    return self.query.get_count(using=self.db)
  File "/home/ryan/projects/villages/django/db/models/sql/", line 406, in get_count
    number = obj.get_aggregation(using=using)[None]
  File "/home/ryan/projects/villages/django/db/models/sql/", line 372, in get_aggregation
    result = query.get_compiler(using).execute_sql(SINGLE)
  File "/home/ryan/projects/villages/django/db/models/sql/", line 754, in execute_sql
    cursor.execute(sql, params)
  File "/home/ryan/projects/villages/django/db/backends/postgresql_psycopg2/", line 43, in execute
    return self.cursor.execute(query, args)
django.db.utils.DatabaseError: relation "django_site" does not exist
LINE 1: SELECT COUNT(*) FROM "django_site"

The problem seems to come from django.db.backends.creation.BaseDatabaseCreation.create_test_db, line 256, which checks if sites is installed, and then proceeds to query the sites table on the current database without checking that the sites table has even been created on the current database.

        Site = get_model('sites', 'Site')
  --->  if Site is not None and Site.objects.using(self.connection.alias).count() == 1:

This code was introduced in [16027].

Change History (2)

comment:1 Changed 8 years ago by Ryan Fugger

Cc: arv@… added

comment:2 Changed 8 years ago by Aymeric Augustin

Resolution: duplicate
Status: newclosed

This really looks like #16353.

Note: See TracTickets for help on using tickets.
Back to Top