Ticket #24817: ticket_24817.patch

File ticket_24817.patch, 2.3 KB (added by Andriy Sokolovskiy, 9 years ago)

Test to reproduce the issue

  • tests/schema/models.py

    diff --git a/tests/schema/models.py b/tests/schema/models.py
    index 07b9496..d50caf9 100644
    a b class Note(models.Model):  
    8787        apps = new_apps
    8888
    8989
     90class NoteRename(models.Model):
     91    detail_info = models.TextField()
     92
     93    class Meta:
     94        apps = new_apps
     95        db_table = "schema_note"
     96
     97
    9098class Tag(models.Model):
    9199    title = models.CharField(max_length=255)
    92100    slug = models.SlugField(unique=True)
  • tests/schema/tests.py

    diff --git a/tests/schema/tests.py b/tests/schema/tests.py
    index 67a3738..908a423 100644
    a b from django.test import TransactionTestCase, skipIfDBFeature  
    2020from .fields import CustomManyToManyField, InheritedManyToManyField
    2121from .models import (
    2222    Author, AuthorWithDefaultHeight, AuthorWithEvenLongerName, Book, BookWeak,
    23     BookWithLongName, BookWithO2O, BookWithSlug, Note, Tag, TagIndexed,
     23    BookWithLongName, BookWithO2O, BookWithSlug, Note, NoteRename, Tag, TagIndexed,
    2424    TagM2MTest, TagUniqueRename, Thing, UniqueTest, new_apps,
    2525)
    2626
    class SchemaTests(TransactionTestCase):  
    751751        self.assertEqual(columns['display_name'][0], "CharField")
    752752        self.assertNotIn("name", columns)
    753753
     754    @skipIfDBFeature('interprets_empty_strings_as_nulls')
     755    def test_rename_keep_null_status(self):
     756        """
     757        Renaming a field shouldn't affect the not null status.
     758        """
     759        with connection.schema_editor() as editor:
     760            editor.create_model(Note)
     761        with self.assertRaises(IntegrityError):
     762            Note.objects.create(info=None)
     763        old_field = Note._meta.get_field("info")
     764        new_field = TextField()
     765        new_field.set_attributes_from_name("detail_info")
     766        with connection.schema_editor() as editor:
     767            editor.alter_field(Note, old_field, new_field, strict=True)
     768        columns = self.column_classes(Note)
     769        self.assertEqual(columns['detail_info'][0], "TextField")
     770        self.assertNotIn("info", columns)
     771        with self.assertRaises(IntegrityError):
     772            NoteRename.objects.create(detail_info=None)
     773
    754774    def _test_m2m_create(self, M2MFieldClass):
    755775        """
    756776        Tests M2M fields on models during creation
Back to Top