1
0
mirror of https://github.com/django/django.git synced 2025-10-24 06:06:09 +00:00

[5.2.x] Fixed #36061 -- Added migration support for ManyToManyField.through_fields.

Added through_fields support to ManyToManyField.deconstruct.
Thanks to Simon Charette for pointers and the review.

Backport of b13b8684a0 from main.
This commit is contained in:
brian
2025-01-06 17:50:44 -08:00
committed by Sarah Boyce
parent 8aea6b802c
commit b96e4c04b6
3 changed files with 20 additions and 0 deletions

View File

@@ -516,6 +516,23 @@ class FieldDeconstructionTests(SimpleTestCase):
self.assertEqual(path, "django.db.models.ManyToManyField")
self.assertEqual(args, [])
self.assertEqual(kwargs, {"to": "auth.permission", "through": "auth.Group"})
# Test through_fields
field = models.ManyToManyField(
"auth.Permission",
through="auth.Group",
through_fields=("foo", "permissions"),
)
name, path, args, kwargs = field.deconstruct()
self.assertEqual(path, "django.db.models.ManyToManyField")
self.assertEqual(args, [])
self.assertEqual(
kwargs,
{
"to": "auth.permission",
"through": "auth.Group",
"through_fields": ("foo", "permissions"),
},
)
# Test custom db_table
field = models.ManyToManyField("auth.Permission", db_table="custom_table")
name, path, args, kwargs = field.deconstruct()