summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorStephen Burrows <stephen.r.burrows@gmail.com>2014-03-21 00:52:49 -0700
committerTim Graham <timograham@gmail.com>2014-03-25 07:46:48 -0400
commitb4f165fe941b1aaca49e417330103a02fecb2e85 (patch)
treefb8a7620e0a59096f8293b1256f20118ee999f2e /tests
parent21eaad68e6f26b9f88437c63d584c0a9fb39c9be (diff)
[1.7.x] Fixed #22300 -- Fixed crash in migrations when changing non-relational field to relational.
Backport of 35ed792cf2 from master
Diffstat (limited to 'tests')
-rw-r--r--tests/migrations/test_autodetector.py23
1 files changed, 23 insertions, 0 deletions
diff --git a/tests/migrations/test_autodetector.py b/tests/migrations/test_autodetector.py
index 40e540ddf2..cb628de269 100644
--- a/tests/migrations/test_autodetector.py
+++ b/tests/migrations/test_autodetector.py
@@ -19,6 +19,7 @@ class AutodetectorTests(TestCase):
author_name_default = ModelState("testapp", "Author", [("id", models.AutoField(primary_key=True)), ("name", models.CharField(max_length=200, default='Ada Lovelace'))])
author_with_book = ModelState("testapp", "Author", [("id", models.AutoField(primary_key=True)), ("name", models.CharField(max_length=200)), ("book", models.ForeignKey("otherapp.Book"))])
author_renamed_with_book = ModelState("testapp", "Writer", [("id", models.AutoField(primary_key=True)), ("name", models.CharField(max_length=200)), ("book", models.ForeignKey("otherapp.Book"))])
+ author_with_publisher_string = ModelState("testapp", "Author", [("id", models.AutoField(primary_key=True)), ("name", models.CharField(max_length=200)), ("publisher_name", models.CharField(max_length=200))])
author_with_publisher = ModelState("testapp", "Author", [("id", models.AutoField(primary_key=True)), ("name", models.CharField(max_length=200)), ("publisher", models.ForeignKey("testapp.Publisher"))])
author_with_custom_user = ModelState("testapp", "Author", [("id", models.AutoField(primary_key=True)), ("name", models.CharField(max_length=200)), ("user", models.ForeignKey("thirdapp.CustomUser"))])
author_proxy = ModelState("testapp", "AuthorProxy", [], {"proxy": True}, ("testapp.author", ))
@@ -517,3 +518,25 @@ class AutodetectorTests(TestCase):
action = migration.operations[0]
self.assertEqual(action.__class__.__name__, "AddField")
self.assertEqual(action.name, "name")
+
+ def test_replace_string_with_foreignkey(self):
+ """
+ Adding an FK in the same "spot" as a deleted CharField should work. (#22300).
+ """
+ # Make state
+ before = self.make_project_state([self.author_with_publisher_string])
+ after = self.make_project_state([self.author_with_publisher])
+ autodetector = MigrationAutodetector(before, after)
+ changes = autodetector._detect_changes()
+ # Right number of migrations?
+ self.assertEqual(len(changes['testapp']), 1)
+ # Right number of actions?
+ migration = changes['testapp'][0]
+ self.assertEqual(len(migration.operations), 2)
+ # Right actions?
+ action = migration.operations[0]
+ self.assertEqual(action.__class__.__name__, "AddField")
+ self.assertEqual(action.name, "publisher")
+ action = migration.operations[1]
+ self.assertEqual(action.__class__.__name__, "RemoveField")
+ self.assertEqual(action.name, "publisher_name")