diff options
| author | Andriy Sokolovskiy <me@asokolovskiy.com> | 2015-05-27 01:18:21 +0300 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2015-05-28 10:08:14 -0400 |
| commit | f65d4db8a805e5184898563542fcb5d459273582 (patch) | |
| tree | ab672b8e45139df4c52bef1491708fe71687caaf /tests | |
| parent | df6a4cac52b58e471168d0a80e5d1900126b7154 (diff) | |
[1.8.x] Fixed #24817 -- Prevented loss of null info in MySQL field renaming.
Backport of 80ad5472ce4b6ba6e94227422d0727371e97cdf0 from master
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/schema/models.py | 8 | ||||
| -rw-r--r-- | tests/schema/tests.py | 24 |
2 files changed, 30 insertions, 2 deletions
diff --git a/tests/schema/models.py b/tests/schema/models.py index 07b9496e14..d50caf9a98 100644 --- a/tests/schema/models.py +++ b/tests/schema/models.py @@ -87,6 +87,14 @@ class Note(models.Model): apps = new_apps +class NoteRename(models.Model): + detail_info = models.TextField() + + class Meta: + apps = new_apps + db_table = "schema_note" + + class Tag(models.Model): title = models.CharField(max_length=255) slug = models.SlugField(unique=True) diff --git a/tests/schema/tests.py b/tests/schema/tests.py index 67a3738fd5..bc007bd451 100644 --- a/tests/schema/tests.py +++ b/tests/schema/tests.py @@ -20,8 +20,8 @@ from django.test import TransactionTestCase, skipIfDBFeature from .fields import CustomManyToManyField, InheritedManyToManyField from .models import ( Author, AuthorWithDefaultHeight, AuthorWithEvenLongerName, Book, BookWeak, - BookWithLongName, BookWithO2O, BookWithSlug, Note, Tag, TagIndexed, - TagM2MTest, TagUniqueRename, Thing, UniqueTest, new_apps, + BookWithLongName, BookWithO2O, BookWithSlug, Note, NoteRename, Tag, + TagIndexed, TagM2MTest, TagUniqueRename, Thing, UniqueTest, new_apps, ) @@ -751,6 +751,26 @@ class SchemaTests(TransactionTestCase): self.assertEqual(columns['display_name'][0], "CharField") self.assertNotIn("name", columns) + @skipIfDBFeature('interprets_empty_strings_as_nulls') + def test_rename_keep_null_status(self): + """ + Renaming a field shouldn't affect the not null status. + """ + with connection.schema_editor() as editor: + editor.create_model(Note) + with self.assertRaises(IntegrityError): + Note.objects.create(info=None) + old_field = Note._meta.get_field("info") + new_field = TextField() + new_field.set_attributes_from_name("detail_info") + with connection.schema_editor() as editor: + editor.alter_field(Note, old_field, new_field, strict=True) + columns = self.column_classes(Note) + self.assertEqual(columns['detail_info'][0], "TextField") + self.assertNotIn("info", columns) + with self.assertRaises(IntegrityError): + NoteRename.objects.create(detail_info=None) + def _test_m2m_create(self, M2MFieldClass): """ Tests M2M fields on models during creation |
