{{{
class Person(models.Model):
first_name = models.CharField(max_length=20)
last_name = models.CharField(max_length=20)
friends = models.ManyToManyField('self')
class AutoIncrementResetTest(TransactionTestCase):
reset_sequences = True
def test_autoincrement_reset1(self):
p = Person.objects.create(first_name='Jack', last_name='Smith')
self.assertEqual(p.pk, 1)
p.friends.add(Person.objects.create(first_name='Jacky',
last_name='Smith'))
self.assertEqual(p.friends.through.objects.first().pk, 1)
def test_autoincrement_reset2(self):
p = Person.objects.create(first_name='Jack', last_name='Smith')
self.assertEqual(p.pk, 1)
p.friends.add(Person.objects.create(first_name='Jacky',
last_name='Smith'))
self.assertEqual(p.friends.through.objects.first().pk, 1)
}}}
Test **test_autoincrement_reset2** will fail with a much higher primary
key, indicating that sequence has not been properly reset. Tested this on
a Postgres database but I assume this error exist on other databases as
well.
--
Ticket URL: <https://code.djangoproject.com/ticket/29559>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* owner: nobody => Oliver Sauder
* status: new => assigned
--
Ticket URL: <https://code.djangoproject.com/ticket/29559#comment:1>
* has_patch: 0 => 1
Comment:
[https://github.com/django/django/pull/10174 PR]
--
Ticket URL: <https://code.djangoproject.com/ticket/29559#comment:2>
* stage: Unreviewed => Ready for checkin
--
Ticket URL: <https://code.djangoproject.com/ticket/29559#comment:3>
* status: assigned => closed
* resolution: => fixed
Comment:
In [changeset:"a07a49ee3295061f384d98d520a565658dd064b8" a07a49ee]:
{{{
#!CommitTicketReference repository=""
revision="a07a49ee3295061f384d98d520a565658dd064b8"
Fixed #29559 -- Fixed TransactionTestCase.reset_sequences for auto-created
m2m through models.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/29559#comment:4>