diff --git a/django/contrib/sites/management.py b/django/contrib/sites/management.py
index daec3d9..507ecd6 100644
a
|
b
|
Creates the default Site object.
|
3 | 3 | """ |
4 | 4 | |
5 | 5 | from django.db.models import signals |
| 6 | from django.db import connections |
6 | 7 | from django.db import router |
7 | 8 | from django.contrib.sites.models import Site |
8 | 9 | from django.contrib.sites import models as site_app |
| 10 | from django.core.management.color import no_style |
9 | 11 | |
10 | 12 | def create_default_site(app, created_models, verbosity, db, **kwargs): |
11 | 13 | # Only create the default sites in databases where Django created the table |
… |
… |
def create_default_site(app, created_models, verbosity, db, **kwargs):
|
19 | 21 | # can also crop up outside of tests - see #15346. |
20 | 22 | s = Site(pk=1, domain="example.com", name="example.com") |
21 | 23 | s.save(using=db) |
| 24 | # Reset the sequence. Above the pk is set explicitly for autofield, so |
| 25 | # make sure the sequence doesn't collide with the above defined ID. |
| 26 | reset_sql = connections[db].ops.sequence_reset_sql(no_style(), [Site]) |
| 27 | cursor = connections[db].cursor() |
| 28 | for command in reset_sql: |
| 29 | cursor.execute(command) |
22 | 30 | Site.objects.clear_cache() |
23 | 31 | |
24 | 32 | signals.post_syncdb.connect(create_default_site, sender=site_app) |
diff --git a/django/contrib/sites/tests.py b/django/contrib/sites/tests.py
index 17ab1f2..4b667b0 100644
a
|
b
|
class SitesFrameworkTests(TestCase):
|
15 | 15 | def tearDown(self): |
16 | 16 | Site._meta.installed = self.old_Site_meta_installed |
17 | 17 | |
| 18 | def test_save_another(self): |
| 19 | """ |
| 20 | On some backends the sequence needs reset after save with explicit ID. |
| 21 | |
| 22 | Test that there is no sequence collisions by saving another site. |
| 23 | """ |
| 24 | Site(domain="example2.com", name="example2.com").save() |
| 25 | |
18 | 26 | def test_site_manager(self): |
19 | 27 | # Make sure that get_current() does not return a deleted Site object. |
20 | 28 | s = Site.objects.get_current() |