summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorTim Graham <timograham@gmail.com>2014-05-01 08:39:58 -0400
committerTim Graham <timograham@gmail.com>2014-05-02 20:53:39 -0400
commitf8fa735dc2a0d06e904b458633d0143820a59ac0 (patch)
treec8f99698b93f96a8f219b2a1bd7430abb0a87db5 /tests
parent61fd00d4fd65f44d0a05be4c7e95124e4102ec27 (diff)
[1.7.x] Fixed #22435 -- Prevented adding a ManyToManyField from prompting for a default.
Thanks andrewsg for the report. Backport of 3818d96426 from master
Diffstat (limited to 'tests')
-rw-r--r--tests/migrations/test_autodetector.py26
1 files changed, 26 insertions, 0 deletions
diff --git a/tests/migrations/test_autodetector.py b/tests/migrations/test_autodetector.py
index c92dda8377..510fd27b0b 100644
--- a/tests/migrations/test_autodetector.py
+++ b/tests/migrations/test_autodetector.py
@@ -37,6 +37,10 @@ class AutodetectorTests(TestCase):
author_proxy_notproxy = ModelState("testapp", "AuthorProxy", [], {}, ("testapp.author", ))
author_unmanaged = ModelState("testapp", "AuthorUnmanaged", [], {"managed": False}, ("testapp.author", ))
author_unmanaged_managed = ModelState("testapp", "AuthorUnmanaged", [], {}, ("testapp.author", ))
+ author_with_m2m = ModelState("testapp", "Author", [
+ ("id", models.AutoField(primary_key=True)),
+ ("publishers", models.ManyToManyField("testapp.Publisher")),
+ ])
publisher = ModelState("testapp", "Publisher", [("id", models.AutoField(primary_key=True)), ("name", models.CharField(max_length=100))])
publisher_with_author = ModelState("testapp", "Publisher", [("id", models.AutoField(primary_key=True)), ("author", models.ForeignKey("testapp.Author")), ("name", models.CharField(max_length=100))])
publisher_with_book = ModelState("testapp", "Publisher", [("id", models.AutoField(primary_key=True)), ("author", models.ForeignKey("otherapp.Book")), ("name", models.CharField(max_length=100))])
@@ -619,6 +623,28 @@ class AutodetectorTests(TestCase):
self.assertEqual(action.__class__.__name__, "DeleteModel")
self.assertEqual(action.name, "Publisher")
+ def test_add_many_to_many(self):
+ """
+ Adding a ManyToManyField should not prompt for a default (#22435).
+ """
+ class CustomQuestioner(MigrationQuestioner):
+ def ask_not_null_addition(self, field_name, model_name):
+ raise Exception("Should not have prompted for not null addition")
+
+ before = self.make_project_state([self.author_empty, self.publisher])
+ # Add ManyToManyField to author model
+ after = self.make_project_state([self.author_with_m2m, self.publisher])
+ autodetector = MigrationAutodetector(before, after, CustomQuestioner())
+ changes = autodetector._detect_changes()
+ # Right number of migrations?
+ self.assertEqual(len(changes['testapp']), 1)
+ migration = changes['testapp'][0]
+ # Right actions in right order?
+ self.assertEqual(len(migration.operations), 1)
+ action = migration.operations[0]
+ self.assertEqual(action.__class__.__name__, "AddField")
+ self.assertEqual(action.name, "publishers")
+
def test_many_to_many_removed_before_through_model(self):
"""
Removing a ManyToManyField and the "through" model in the same change must remove