Ticket #29496: 29496.diff

File 29496.diff, 2.0 KB (added by Mariusz Felisiak, 6 years ago)

Test.

  • tests/schema/models.py

    diff --git a/tests/schema/models.py b/tests/schema/models.py
    index 4512d8bc01..f6bdbd8815 100644
    a b class Author(models.Model):  
    1212    name = models.CharField(max_length=255)
    1313    height = models.PositiveIntegerField(null=True, blank=True)
    1414    weight = models.IntegerField(null=True, blank=True)
     15    uuid = models.UUIDField(null=True)
    1516
    1617    class Meta:
    1718        apps = new_apps
  • tests/schema/tests.py

    diff --git a/tests/schema/tests.py b/tests/schema/tests.py
    index e1bf438ca3..32e4a28e10 100644
    a b from django.db.models.deletion import CASCADE, PROTECT  
    1212from django.db.models.fields import (
    1313    AutoField, BigAutoField, BigIntegerField, BinaryField, BooleanField,
    1414    CharField, DateField, DateTimeField, IntegerField, PositiveIntegerField,
    15     SlugField, TextField, TimeField,
     15    SlugField, TextField, TimeField, UUIDField,
    1616)
    1717from django.db.models.fields.related import (
    1818    ForeignKey, ForeignObject, ManyToManyField, OneToOneField,
    class SchemaTests(TransactionTestCase):  
    603603        with connection.schema_editor() as editor:
    604604            editor.alter_field(Author, old_field, new_field, strict=True)
    605605
     606    def test_alter_nullable_uuid_to_primary_key(self):
     607        # Create the table
     608        with connection.schema_editor() as editor:
     609            editor.create_model(Author)
     610        # Change UUIDField to PrimaryKey
     611        old_field = Author._meta.get_field('uuid')
     612        new_field = UUIDField(primary_key=True)
     613        new_field.set_attributes_from_name('uuid')
     614        new_field.model = Author
     615        with connection.schema_editor() as editor:
     616            editor.remove_field(Author, Author._meta.get_field('id'))
     617            editor.alter_field(Author, old_field, new_field, strict=True)
     618
    606619    def test_alter_text_field(self):
    607620        # Regression for "BLOB/TEXT column 'info' can't have a default value")
    608621        # on MySQL.
Back to Top