From e1347e9253821a31f9896de9eb993e2376e7398f Mon Sep 17 00:00:00 2001 From: Abraham Martin Date: Sat, 26 Jul 2014 18:48:36 +0200 Subject: [PATCH] Fixed #23101 db_table wasn't copied in deconstruct Forward port of 999758fc7a2d6fcb01eb40de937d4420f884788d from stable/1.7.x --- django/db/models/fields/related.py | 2 ++ tests/field_deconstruction/tests.py | 6 ++++++ 2 files changed, 8 insertions(+) diff --git a/django/db/models/fields/related.py b/django/db/models/fields/related.py index 1dc5ff9b1db..7d9c4f9fe83 100644 --- a/django/db/models/fields/related.py +++ b/django/db/models/fields/related.py @@ -2138,6 +2138,8 @@ class ManyToManyField(RelatedField): def deconstruct(self): name, path, args, kwargs = super(ManyToManyField, self).deconstruct() # Handle the simpler arguments + if self.db_table is not None: + kwargs['db_table'] = self.db_table if self.rel.db_constraint is not True: kwargs['db_constraint'] = self.rel.db_constraint if "help_text" in kwargs: diff --git a/tests/field_deconstruction/tests.py b/tests/field_deconstruction/tests.py index 2f0732a60e1..5a424eea3cf 100644 --- a/tests/field_deconstruction/tests.py +++ b/tests/field_deconstruction/tests.py @@ -271,6 +271,12 @@ class FieldDeconstructionTests(TestCase): self.assertEqual(path, "django.db.models.ManyToManyField") self.assertEqual(args, []) self.assertEqual(kwargs, {"to": "auth.Permission", "through": "auth.Group"}) + # Test custom db_table + field = models.ManyToManyField("auth.Permission", db_table="custom_table") + name, path, args, kwargs = field.deconstruct() + self.assertEqual(path, "django.db.models.ManyToManyField") + self.assertEqual(args, []) + self.assertEqual(kwargs, {"to": "auth.Permission", "db_table": "custom_table"}) @override_settings(AUTH_USER_MODEL="auth.Permission") def test_many_to_many_field_swapped(self):