diff options
| author | Jordan Bae <qoentlr37@naver.com> | 2021-02-07 01:01:34 +0900 |
|---|---|---|
| committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2021-02-09 08:25:05 +0100 |
| commit | 9eed258283f369dcb0ae0b84b4a1b24bf374db7b (patch) | |
| tree | 00e95c5795ca9eb650789669e71ad552d34a9942 /tests | |
| parent | bae685f267202b0d6250a402e675be006cb9699b (diff) | |
[3.2.x] Fixed #32425 -- Fixed adding nullable field with default on MySQL.
Thanks Simon Charette for the review.
Backport of d4ac23bee1c84d8e4610350202ac068fc90f38c0 from master
Diffstat (limited to 'tests')
| -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 b994c252d9..4522f5faf4 100644 --- a/tests/schema/tests.py +++ b/tests/schema/tests.py @@ -3095,6 +3095,33 @@ class SchemaTests(TransactionTestCase): if connection.features.can_introspect_default: self.assertIsNone(field.default) + def test_add_field_default_nullable(self): + with connection.schema_editor() as editor: + editor.create_model(Author) + # Add new nullable CharField with a default. + new_field = CharField(max_length=15, blank=True, null=True, default='surname') + new_field.set_attributes_from_name('surname') + 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 surname 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 == 'surname' + ) + # 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: |
