summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Godwin <andrew@aeracode.org>2014-07-21 10:14:00 +0100
committerAndrew Godwin <andrew@aeracode.org>2014-07-21 10:14:00 +0100
commitdcb4ed517082d13ccf7da9bd5d16c77bcecbf139 (patch)
tree0d85eb0fc850b10985fda54ea8f4d9367ac1dac8
parent2984b30ce84eccedfcc5b5241d12720913d0b80a (diff)
Fixed #22975: Don't call rename SQL if not needed
-rw-r--r--django/db/backends/schema.py2
-rw-r--r--tests/migrations/test_operations.py20
2 files changed, 22 insertions, 0 deletions
diff --git a/django/db/backends/schema.py b/django/db/backends/schema.py
index d4573a4be8..a82524b2a0 100644
--- a/django/db/backends/schema.py
+++ b/django/db/backends/schema.py
@@ -367,6 +367,8 @@ class BaseDatabaseSchemaEditor(object):
"""
Renames the table a model points to.
"""
+ if old_db_table == new_db_table:
+ return
self.execute(self.sql_rename_table % {
"old_table": self.quote_name(old_db_table),
"new_table": self.quote_name(new_db_table),
diff --git a/tests/migrations/test_operations.py b/tests/migrations/test_operations.py
index b8d1ae5819..7e3e030518 100644
--- a/tests/migrations/test_operations.py
+++ b/tests/migrations/test_operations.py
@@ -769,6 +769,26 @@ class OperationTests(OperationTestBase):
self.assertTableExists("test_almota_pony")
self.assertTableNotExists("test_almota_pony_2")
+ def test_alter_model_table_noop(self):
+ """
+ Tests the AlterModelTable operation if the table name is not changed.
+ """
+ project_state = self.set_up_test_model("test_almota")
+ # Test the state alteration
+ operation = migrations.AlterModelTable("Pony", "test_almota_pony")
+ new_state = project_state.clone()
+ operation.state_forwards("test_almota", new_state)
+ self.assertEqual(new_state.models["test_almota", "pony"].options["db_table"], "test_almota_pony")
+ # Test the database alteration
+ self.assertTableExists("test_almota_pony")
+ with connection.schema_editor() as editor:
+ operation.database_forwards("test_almota", editor, project_state, new_state)
+ self.assertTableExists("test_almota_pony")
+ # And test reversal
+ with connection.schema_editor() as editor:
+ operation.database_backwards("test_almota", editor, new_state, project_state)
+ self.assertTableExists("test_almota_pony")
+
def test_alter_field(self):
"""
Tests the AlterField operation.