diff --git a/django/db/backends/postgresql/operations.py b/django/db/backends/postgresql/operations.py
index 76f2541..785d301 100644
a
|
b
|
class DatabaseOperations(BaseDatabaseOperations):
|
132 | 132 | if not f.rel.through: |
133 | 133 | output.append("%s setval(pg_get_serial_sequence('%s','%s'), coalesce(max(%s), 1), max(%s) %s null) %s %s;" % \ |
134 | 134 | (style.SQL_KEYWORD('SELECT'), |
135 | | style.SQL_TABLE(model._meta.db_table), |
| 135 | style.SQL_TABLE(qn(f.m2m_db_table())), |
136 | 136 | style.SQL_FIELD('id'), |
137 | 137 | style.SQL_FIELD(qn('id')), |
138 | 138 | style.SQL_FIELD(qn('id')), |
diff --git a/tests/regressiontests/backends/models.py b/tests/regressiontests/backends/models.py
index e3137f2..c985573 100644
a
|
b
|
from django.conf import settings
|
2 | 2 | from django.db import models |
3 | 3 | from django.db import connection, DEFAULT_DB_ALIAS |
4 | 4 | |
| 5 | from django.contrib.contenttypes import generic |
| 6 | from django.contrib.contenttypes.models import ContentType |
| 7 | |
| 8 | |
5 | 9 | |
6 | 10 | class Square(models.Model): |
7 | 11 | root = models.IntegerField() |
… |
… |
if settings.DATABASES[DEFAULT_DB_ALIAS]['ENGINE'] != 'django.db.backends.mysql':
|
37 | 41 | m2m_also_quite_long_zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz = models.ManyToManyField(Person,blank=True) |
38 | 42 | |
39 | 43 | |
| 44 | class Tag(models.Model): |
| 45 | name = models.CharField(max_length=30) |
| 46 | content_type = models.ForeignKey(ContentType) |
| 47 | object_id = models.PositiveIntegerField() |
| 48 | content_object = generic.GenericForeignKey('content_type', 'object_id') |
| 49 | |
| 50 | |
| 51 | class Post(models.Model): |
| 52 | name = models.CharField(max_length=30) |
| 53 | text = models.TextField() |
| 54 | tags = generic.GenericRelation('Tag') |
| 55 | |
| 56 | |
40 | 57 | qn = connection.ops.quote_name |
41 | 58 | |
42 | 59 | __test__ = {'API_TESTS': """ |
diff --git a/tests/regressiontests/backends/tests.py b/tests/regressiontests/backends/tests.py
index ee3ccdc..146ff27 100644
a
|
b
|
import unittest
|
6 | 6 | from django.conf import settings |
7 | 7 | from django.core import management |
8 | 8 | from django.core.management.color import no_style |
9 | | from django.db import backend, connection, DEFAULT_DB_ALIAS |
| 9 | from django.db import backend, connection, connections, DEFAULT_DB_ALIAS |
10 | 10 | from django.db.backends.signals import connection_created |
11 | 11 | from django.test import TestCase |
12 | 12 | |
… |
… |
if settings.DATABASES[DEFAULT_DB_ALIAS]['ENGINE'] != 'django.db.backends.mysql':
|
137 | 137 | for statement in connection.ops.sql_flush(no_style(), tables, sequences): |
138 | 138 | cursor.execute(statement) |
139 | 139 | |
| 140 | if settings.DATABASES[DEFAULT_DB_ALIAS]['ENGINE'] == 'django.db.backends.postgresql_psycopg2': |
| 141 | class PostgresResetSequenceTest(TestCase): |
| 142 | |
| 143 | def test_generic_relation(self): |
| 144 | cursor = connection.cursor() |
| 145 | models.Post.objects.create(id=10, name='1st post', text='hello world') |
| 146 | commands = connections[DEFAULT_DB_ALIAS].ops.sequence_reset_sql(no_style(), [models.Post]) |
| 147 | for sql in commands: |
| 148 | cursor.execute(sql) |
| 149 | cursor.execute("SELECT nextval(pg_get_serial_sequence('backends_post','id'))") |
| 150 | self.assertEqual(cursor.fetchone()[0], 11) |
| 151 | |
| 152 | |
| 153 | |
140 | 154 | |
141 | 155 | def connection_created_test(sender, **kwargs): |
142 | 156 | print 'connection_created signal' |