summaryrefslogtreecommitdiff
path: root/tests/schema
diff options
context:
space:
mode:
authorSimon Charette <charette.s@gmail.com>2016-05-24 15:29:11 -0400
committerSimon Charette <charette.s@gmail.com>2017-06-21 00:26:30 -0400
commitb50815ee418b38e719476c2d5f6e2bc69f686927 (patch)
tree0778cf9501e342e2a8a8a7cf3967839617e773d7 /tests/schema
parent3b429c96736b8328c40e5d77282b0d30de563c3c (diff)
Refs #25530 -- Renamed deferred SQL references on rename operation.
Diffstat (limited to 'tests/schema')
-rw-r--r--tests/schema/tests.py29
1 files changed, 29 insertions, 0 deletions
diff --git a/tests/schema/tests.py b/tests/schema/tests.py
index d2707ecea7..f4612a5dee 100644
--- a/tests/schema/tests.py
+++ b/tests/schema/tests.py
@@ -2359,3 +2359,32 @@ class SchemaTests(TransactionTestCase):
doc = Document.objects.create(name='Test Name')
student = Student.objects.create(name='Some man')
doc.students.add(student)
+
+ def test_rename_table_renames_deferred_sql_references(self):
+ with connection.schema_editor() as editor:
+ editor.create_model(Author)
+ editor.create_model(Book)
+ editor.alter_db_table(Author, 'schema_author', 'schema_renamed_author')
+ editor.alter_db_table(Author, 'schema_book', 'schema_renamed_book')
+ self.assertGreater(len(editor.deferred_sql), 0)
+ for statement in editor.deferred_sql:
+ self.assertIs(statement.references_table('schema_author'), False)
+ self.assertIs(statement.references_table('schema_book'), False)
+
+ @unittest.skipIf(connection.vendor == 'sqlite', 'SQLite naively remakes the table on field alteration.')
+ def test_rename_column_renames_deferred_sql_references(self):
+ with connection.schema_editor() as editor:
+ editor.create_model(Author)
+ editor.create_model(Book)
+ old_title = Book._meta.get_field('title')
+ new_title = CharField(max_length=100, db_index=True)
+ new_title.set_attributes_from_name('renamed_title')
+ editor.alter_field(Book, old_title, new_title)
+ old_author = Book._meta.get_field('author')
+ new_author = ForeignKey(Author, CASCADE)
+ new_author.set_attributes_from_name('renamed_author')
+ editor.alter_field(Book, old_author, new_author)
+ self.assertGreater(len(editor.deferred_sql), 0)
+ for statement in editor.deferred_sql:
+ self.assertIs(statement.references_column('book', 'title'), False)
+ self.assertIs(statement.references_column('book', 'author_id'), False)