diff options
Diffstat (limited to 'tests/schema')
| -rw-r--r-- | tests/schema/tests.py | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/tests/schema/tests.py b/tests/schema/tests.py index abcaa5b480..833611df3a 100644 --- a/tests/schema/tests.py +++ b/tests/schema/tests.py @@ -1956,6 +1956,21 @@ class SchemaTests(TransactionTestCase): if connection.features.can_introspect_default: self.assertIsNone(field.default) + @unittest.skipIf(connection.vendor == 'sqlite', 'SQLite naively remakes the table on field alteration.') + def test_alter_field_default_doesnt_perfom_queries(self): + """ + No queries are performed if a field default changes and the field's + not changing from null to non-null. + """ + with connection.schema_editor() as editor: + editor.create_model(AuthorWithDefaultHeight) + old_field = AuthorWithDefaultHeight._meta.get_field('height') + new_default = old_field.default * 2 + new_field = PositiveIntegerField(null=True, blank=True, default=new_default) + new_field.set_attributes_from_name('height') + with connection.schema_editor() as editor, self.assertNumQueries(0): + editor.alter_field(AuthorWithDefaultHeight, old_field, new_field, strict=True) + def test_add_textfield_unhashable_default(self): # Create the table with connection.schema_editor() as editor: |
