mirror of
https://github.com/django/django.git
synced 2025-10-24 06:06:09 +00:00
Fixed #24135 -- Made RenameModel rename many-to-many tables.
Thanks Simon and Markus for reviews.
This commit is contained in:
@@ -553,6 +553,32 @@ class OperationTests(OperationTestBase):
|
||||
pony = Pony.objects.create()
|
||||
pony.ponies.add(pony)
|
||||
|
||||
def test_rename_model_with_m2m(self):
|
||||
app_label = "test_rename_model_with_m2m"
|
||||
project_state = self.apply_operations(app_label, ProjectState(), operations=[
|
||||
migrations.CreateModel("Rider", fields=[]),
|
||||
migrations.CreateModel("Pony", fields=[
|
||||
("riders", models.ManyToManyField("Rider")),
|
||||
]),
|
||||
])
|
||||
Pony = project_state.apps.get_model(app_label, "Pony")
|
||||
Rider = project_state.apps.get_model(app_label, "Rider")
|
||||
pony = Pony.objects.create()
|
||||
rider = Rider.objects.create()
|
||||
pony.riders.add(rider)
|
||||
|
||||
project_state = self.apply_operations(app_label, project_state, operations=[
|
||||
migrations.RenameModel("Pony", "Pony2"),
|
||||
])
|
||||
Pony = project_state.apps.get_model(app_label, "Pony2")
|
||||
Rider = project_state.apps.get_model(app_label, "Rider")
|
||||
pony = Pony.objects.create()
|
||||
rider = Rider.objects.create()
|
||||
pony.riders.add(rider)
|
||||
self.assertEqual(Pony.objects.count(), 2)
|
||||
self.assertEqual(Rider.objects.count(), 2)
|
||||
self.assertEqual(Pony._meta.get_field('riders').rel.through.objects.count(), 2)
|
||||
|
||||
def test_add_field(self):
|
||||
"""
|
||||
Tests the AddField operation.
|
||||
|
||||
Reference in New Issue
Block a user