diff options
author | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2021-06-10 09:39:08 +0200 |
---|---|---|
committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2021-06-10 20:03:43 +0200 |
commit | fa0433d05f213afe4c67055006320f7aba4c8108 (patch) | |
tree | 895cee75aa1ed87bff36fdec0642c8662d147469 /tests/schema | |
parent | 57bc16b38ec75fc96829f912d57a58d8c6358e8f (diff) | |
download | django-fa0433d05f213afe4c67055006320f7aba4c8108.tar.gz |
Fixed #32832 -- Fixed adding BLOB/TEXT nullable field with default on MySQL 8.0.13+.
Regression in d4ac23bee1c84d8e4610350202ac068fc90f38c0.
Thanks Omkar Deshpande for the report.
Diffstat (limited to 'tests/schema')
-rw-r--r-- | tests/schema/tests.py | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/tests/schema/tests.py b/tests/schema/tests.py index eb9be178db..0e88bfdbd1 100644 --- a/tests/schema/tests.py +++ b/tests/schema/tests.py @@ -3387,6 +3387,33 @@ class SchemaTests(TransactionTestCase): if connection.features.can_introspect_default: self.assertIn(field.default, ['NULL', None]) + def test_add_textfield_default_nullable(self): + with connection.schema_editor() as editor: + editor.create_model(Author) + # Add new nullable TextField with a default. + new_field = TextField(blank=True, null=True, default='text') + new_field.set_attributes_from_name('description') + with connection.schema_editor() as editor: + editor.add_field(Author, new_field) + Author.objects.create(name='Anonymous1') + with connection.cursor() as cursor: + cursor.execute('SELECT description FROM schema_author;') + item = cursor.fetchall()[0] + self.assertIsNone(item[0]) + field = next( + f + for f in connection.introspection.get_table_description( + cursor, + 'schema_author', + ) + if f.name == 'description' + ) + # Field is still nullable. + self.assertTrue(field.null_ok) + # The database default is no longer set. + if connection.features.can_introspect_default: + self.assertIn(field.default, ['NULL', None]) + def test_alter_field_default_dropped(self): # Create the table with connection.schema_editor() as editor: |