Loading django/db/backends/schema.py +1 −1 Original line number Diff line number Diff line Loading @@ -552,7 +552,7 @@ class BaseDatabaseSchemaEditor(object): # Default change? old_default = self.effective_default(old_field) new_default = self.effective_default(new_field) if old_default != new_default: if old_default != new_default and not self.skip_default(new_field): if new_default is None: actions.append(( self.sql_alter_column_no_default % { Loading docs/releases/1.7.2.txt +4 −1 Original line number Diff line number Diff line Loading @@ -107,4 +107,7 @@ Bugfixes * Prevented the :class:`~django.contrib.auth.middleware.SessionAuthenticationMiddleware` from setting a ``"Vary: Cookie"`` header on all responses. setting a ``"Vary: Cookie"`` header on all responses (:ticket:`23939`). * Fixed a crash when adding ``blank=True`` to ``TextField()`` on MySQL (:ticket:`23920`). tests/schema/models.py +4 −0 Original line number Diff line number Diff line Loading @@ -171,3 +171,7 @@ class Thing(models.Model): def __str__(self): return self.when class Note(models.Model): info = models.TextField() tests/schema/tests.py +14 −1 Original line number Diff line number Diff line Loading @@ -10,7 +10,7 @@ from django.db.transaction import atomic from .models import (Author, AuthorWithDefaultHeight, AuthorWithM2M, Book, BookWithLongName, BookWithSlug, BookWithM2M, Tag, TagIndexed, TagM2MTest, TagUniqueRename, UniqueTest, Thing, TagThrough, BookWithM2MThrough, AuthorTag, AuthorWithM2MThrough, AuthorWithEvenLongerName, BookWeak) AuthorWithEvenLongerName, BookWeak, Note) class SchemaTests(TransactionTestCase): Loading Loading @@ -416,6 +416,19 @@ class SchemaTests(TransactionTestCase): self.assertEqual(columns['name'][0], "TextField") self.assertEqual(bool(columns['name'][1][6]), False) def test_alter_text_field(self): # Regression for "BLOB/TEXT column 'info' can't have a default value") # on MySQL. new_field = TextField(blank=True) new_field.set_attributes_from_name("info") with connection.schema_editor() as editor: editor.alter_field( Note, Note._meta.get_field_by_name("info")[0], new_field, strict=True, ) def test_alter_null_to_not_null(self): """ #23609 - Tests handling of default values when altering from NULL to NOT NULL. Loading Loading
django/db/backends/schema.py +1 −1 Original line number Diff line number Diff line Loading @@ -552,7 +552,7 @@ class BaseDatabaseSchemaEditor(object): # Default change? old_default = self.effective_default(old_field) new_default = self.effective_default(new_field) if old_default != new_default: if old_default != new_default and not self.skip_default(new_field): if new_default is None: actions.append(( self.sql_alter_column_no_default % { Loading
docs/releases/1.7.2.txt +4 −1 Original line number Diff line number Diff line Loading @@ -107,4 +107,7 @@ Bugfixes * Prevented the :class:`~django.contrib.auth.middleware.SessionAuthenticationMiddleware` from setting a ``"Vary: Cookie"`` header on all responses. setting a ``"Vary: Cookie"`` header on all responses (:ticket:`23939`). * Fixed a crash when adding ``blank=True`` to ``TextField()`` on MySQL (:ticket:`23920`).
tests/schema/models.py +4 −0 Original line number Diff line number Diff line Loading @@ -171,3 +171,7 @@ class Thing(models.Model): def __str__(self): return self.when class Note(models.Model): info = models.TextField()
tests/schema/tests.py +14 −1 Original line number Diff line number Diff line Loading @@ -10,7 +10,7 @@ from django.db.transaction import atomic from .models import (Author, AuthorWithDefaultHeight, AuthorWithM2M, Book, BookWithLongName, BookWithSlug, BookWithM2M, Tag, TagIndexed, TagM2MTest, TagUniqueRename, UniqueTest, Thing, TagThrough, BookWithM2MThrough, AuthorTag, AuthorWithM2MThrough, AuthorWithEvenLongerName, BookWeak) AuthorWithEvenLongerName, BookWeak, Note) class SchemaTests(TransactionTestCase): Loading Loading @@ -416,6 +416,19 @@ class SchemaTests(TransactionTestCase): self.assertEqual(columns['name'][0], "TextField") self.assertEqual(bool(columns['name'][1][6]), False) def test_alter_text_field(self): # Regression for "BLOB/TEXT column 'info' can't have a default value") # on MySQL. new_field = TextField(blank=True) new_field.set_attributes_from_name("info") with connection.schema_editor() as editor: editor.alter_field( Note, Note._meta.get_field_by_name("info")[0], new_field, strict=True, ) def test_alter_null_to_not_null(self): """ #23609 - Tests handling of default values when altering from NULL to NOT NULL. Loading