Fixed #23101 db_table wasn't copied in deconstruct
This commit is contained in:
parent
7e708a2536
commit
999758fc7a
|
@ -2088,6 +2088,8 @@ class ManyToManyField(RelatedField):
|
||||||
def deconstruct(self):
|
def deconstruct(self):
|
||||||
name, path, args, kwargs = super(ManyToManyField, self).deconstruct()
|
name, path, args, kwargs = super(ManyToManyField, self).deconstruct()
|
||||||
# Handle the simpler arguments
|
# 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:
|
if self.rel.db_constraint is not True:
|
||||||
kwargs['db_constraint'] = self.rel.db_constraint
|
kwargs['db_constraint'] = self.rel.db_constraint
|
||||||
if "help_text" in kwargs:
|
if "help_text" in kwargs:
|
||||||
|
|
|
@ -271,6 +271,12 @@ class FieldDeconstructionTests(TestCase):
|
||||||
self.assertEqual(path, "django.db.models.ManyToManyField")
|
self.assertEqual(path, "django.db.models.ManyToManyField")
|
||||||
self.assertEqual(args, [])
|
self.assertEqual(args, [])
|
||||||
self.assertEqual(kwargs, {"to": "auth.Permission", "through": "auth.Group"})
|
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")
|
@override_settings(AUTH_USER_MODEL="auth.Permission")
|
||||||
def test_many_to_many_field_swapped(self):
|
def test_many_to_many_field_swapped(self):
|
||||||
|
|
Loading…
Reference in New Issue