summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOliver Sauder <oliver.sauder@adfinis-sygroup.ch>2018-07-11 10:18:41 +0200
committerTim Graham <timograham@gmail.com>2018-07-11 17:20:29 -0400
commita07a49ee3295061f384d98d520a565658dd064b8 (patch)
treea31447a8f5b09c51a6add14b0c673b102d05cec6
parent4d98b9d729fa7f2525f346fbaf180030c3c3a5f8 (diff)
Fixed #29559 -- Fixed TransactionTestCase.reset_sequences for auto-created m2m through models.
-rw-r--r--django/db/backends/base/introspection.py2
-rw-r--r--tests/test_runner/models.py1
-rw-r--r--tests/test_runner/tests.py3
3 files changed, 5 insertions, 1 deletions
diff --git a/django/db/backends/base/introspection.py b/django/db/backends/base/introspection.py
index 8fe8966a21..cefdecea0a 100644
--- a/django/db/backends/base/introspection.py
+++ b/django/db/backends/base/introspection.py
@@ -127,7 +127,7 @@ class BaseDatabaseIntrospection:
for f in model._meta.local_many_to_many:
# If this is an m2m using an intermediate table,
# we don't need to reset the sequence.
- if f.remote_field.through is None:
+ if f.remote_field.through._meta.auto_created:
sequence = self.get_sequences(cursor, f.m2m_db_table())
sequence_list.extend(sequence or [{'table': f.m2m_db_table(), 'column': None}])
return sequence_list
diff --git a/tests/test_runner/models.py b/tests/test_runner/models.py
index ea6d2cc499..9b26dbfc1e 100644
--- a/tests/test_runner/models.py
+++ b/tests/test_runner/models.py
@@ -4,6 +4,7 @@ from django.db import models
class Person(models.Model):
first_name = models.CharField(max_length=20)
last_name = models.CharField(max_length=20)
+ friends = models.ManyToManyField('self')
# A set of models that use a non-abstract inherited 'through' model.
diff --git a/tests/test_runner/tests.py b/tests/test_runner/tests.py
index bf54e5f840..65224538e9 100644
--- a/tests/test_runner/tests.py
+++ b/tests/test_runner/tests.py
@@ -342,6 +342,9 @@ class AutoIncrementResetTest(TransactionTestCase):
# Regular model
p = Person.objects.create(first_name='Jack', last_name='Smith')
self.assertEqual(p.pk, 1)
+ # Auto-created many-to-many through model
+ p.friends.add(Person.objects.create(first_name='Jacky', last_name='Smith'))
+ self.assertEqual(p.friends.through.objects.first().pk, 1)
# Many-to-many through model
b = B.objects.create()
t = Through.objects.create(person=p, b=b)