mirror of
https://github.com/django/django.git
synced 2025-08-04 10:59:45 +00:00
Fixed #24725 -- Allowed renaming of target models in ManyToMany relations
This is a regression caused by introducing rendered migration states in1aa3e09c20
and the _meta refactoring infb48eb0581
. Thanks to Danilo Bargen for reporting the issue and Marten Kenbeek and Tim Graham for triaging the bug and providing the initial test case.
This commit is contained in:
parent
cf34ee68f0
commit
63f9b633f9
3 changed files with 30 additions and 1 deletions
|
@ -614,6 +614,32 @@ class OperationTests(OperationTestBase):
|
|||
self.assertEqual(Rider.objects.count(), 2)
|
||||
self.assertEqual(Pony._meta.get_field('riders').remote_field.through.objects.count(), 2)
|
||||
|
||||
def test_rename_m2m_target_model(self):
|
||||
app_label = "test_rename_m2m_target_model"
|
||||
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("Rider", "Rider2"),
|
||||
])
|
||||
Pony = project_state.apps.get_model(app_label, "Pony")
|
||||
Rider = project_state.apps.get_model(app_label, "Rider2")
|
||||
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').remote_field.through.objects.count(), 2)
|
||||
|
||||
def test_add_field(self):
|
||||
"""
|
||||
Tests the AddField operation.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue