﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
16353	With multi-databases, if django.contrib.sites.models.Site is not synchronized on all databases, Django's tests fail	Aymeric Augustin	nobody	"Here are the detailed steps to reproduce (in a fresh checkout):

{{{
$ PYTHONPATH=. django/bin/django-admin.py startproject testproj
$ cd testproj
$ PYTHONPATH=.. ./manage.py startapp testapp
$ vi settings.py
}}}

{{{
DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': 'default.sqlite3',
    },
    'other': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': 'other.sqlite3',
    }
}

DATABASE_ROUTERS = ['testapp.routers.MyAppRouter']
}}}

{{{
$ vi testapp/routers.py
}}}

{{{
class MyAppRouter(object):

    def db_for_read(self, model, **hints):
        return 'other' if model._meta.app_label == 'testapp' else 'default'

    def db_for_write(self, model, **hints):
        return 'other' if model._meta.app_label == 'testapp' else 'default'

    def allow_relation(self, obj1, obj2, **hints):
        pass

    def allow_syncdb(self, db, model):
        return db == ('other' if model._meta.app_label == 'testapp' else 'default')
}}}

{{{
$ PYTHONPATH=.. ./manage.py test
Creating test database for alias 'default'...
Creating test database for alias 'other'...
Traceback (most recent call last):
  File ""./manage.py"", line 14, in <module>
    execute_manager(settings)
  File ""/Users/myk/Desktop/django-trunk/django/core/management/__init__.py"", line 442, in execute_manager
    utility.execute()
  File ""/Users/myk/Desktop/django-trunk/django/core/management/__init__.py"", line 379, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File ""/Users/myk/Desktop/django-trunk/django/core/management/commands/test.py"", line 34, in run_from_argv
    super(Command, self).run_from_argv(argv)
  File ""/Users/myk/Desktop/django-trunk/django/core/management/base.py"", line 191, in run_from_argv
    self.execute(*args, **options.__dict__)
  File ""/Users/myk/Desktop/django-trunk/django/core/management/base.py"", line 220, in execute
    output = self.handle(*args, **options)
  File ""/Users/myk/Desktop/django-trunk/django/core/management/commands/test.py"", line 54, in handle
    failures = test_runner.run_tests(test_labels)
  File ""/Users/myk/Desktop/django-trunk/django/test/simple.py"", line 354, in run_tests
    old_config = self.setup_databases()
  File ""/Users/myk/Desktop/django-trunk/django/test/simple.py"", line 291, in setup_databases
    test_db_name = connection.creation.create_test_db(self.verbosity, autoclobber=not self.interactive)
  File ""/Users/myk/Desktop/django-trunk/django/db/backends/creation.py"", line 256, in create_test_db
    if Site is not None and Site.objects.using(self.connection.alias).count() == 1:
  File ""/Users/myk/Desktop/django-trunk/django/db/models/query.py"", line 334, in count
    return self.query.get_count(using=self.db)
  File ""/Users/myk/Desktop/django-trunk/django/db/models/sql/query.py"", line 406, in get_count
    number = obj.get_aggregation(using=using)[None]
  File ""/Users/myk/Desktop/django-trunk/django/db/models/sql/query.py"", line 372, in get_aggregation
    result = query.get_compiler(using).execute_sql(SINGLE)
  File ""/Users/myk/Desktop/django-trunk/django/db/models/sql/compiler.py"", line 754, in execute_sql
    cursor.execute(sql, params)
  File ""/Users/myk/Desktop/django-trunk/django/db/backends/sqlite3/base.py"", line 226, in execute
    return Database.Cursor.execute(self, query, params)
django.db.utils.DatabaseError: no such table: django_site
}}}

Attached patch fixes this problem."	Bug	closed	Testing framework	1.3	Release blocker	fixed		ubernostrum@…	Accepted	1	0	0	0	0	0
