diff options
| author | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2018-06-17 08:51:02 +0200 |
|---|---|---|
| committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2018-06-17 08:54:01 +0200 |
| commit | d2ca28db54a5871d851cdd9184f4cf0d31aff946 (patch) | |
| tree | 3c748d68bf15807468918b6a7c960ce7cac70738 /tests | |
| parent | d28360aa48e40af43450dcdd3843fe7b197b898c (diff) | |
[2.1.x] Fixed #29496 -- Fixed crash on Oracle when converting a non-unique field to primary key.
Thanks Tim Graham for the review.
Backport of 6dd4edb1b4f5441c5f543e29395039839c50d10b from master
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/schema/models.py | 1 | ||||
| -rw-r--r-- | tests/schema/tests.py | 15 |
2 files changed, 15 insertions, 1 deletions
diff --git a/tests/schema/models.py b/tests/schema/models.py index 4512d8bc01..f6bdbd8815 100644 --- a/tests/schema/models.py +++ b/tests/schema/models.py @@ -12,6 +12,7 @@ class Author(models.Model): name = models.CharField(max_length=255) height = models.PositiveIntegerField(null=True, blank=True) weight = models.IntegerField(null=True, blank=True) + uuid = models.UUIDField(null=True) class Meta: apps = new_apps diff --git a/tests/schema/tests.py b/tests/schema/tests.py index e1bf438ca3..f18b68d04d 100644 --- a/tests/schema/tests.py +++ b/tests/schema/tests.py @@ -12,7 +12,7 @@ from django.db.models.deletion import CASCADE, PROTECT from django.db.models.fields import ( AutoField, BigAutoField, BigIntegerField, BinaryField, BooleanField, CharField, DateField, DateTimeField, IntegerField, PositiveIntegerField, - SlugField, TextField, TimeField, + SlugField, TextField, TimeField, UUIDField, ) from django.db.models.fields.related import ( ForeignKey, ForeignObject, ManyToManyField, OneToOneField, @@ -603,6 +603,19 @@ class SchemaTests(TransactionTestCase): with connection.schema_editor() as editor: editor.alter_field(Author, old_field, new_field, strict=True) + def test_alter_not_unique_field_to_primary_key(self): + # Create the table. + with connection.schema_editor() as editor: + editor.create_model(Author) + # Change UUIDField to primary key. + old_field = Author._meta.get_field('uuid') + new_field = UUIDField(primary_key=True) + new_field.set_attributes_from_name('uuid') + new_field.model = Author + with connection.schema_editor() as editor: + editor.remove_field(Author, Author._meta.get_field('id')) + editor.alter_field(Author, old_field, new_field, strict=True) + def test_alter_text_field(self): # Regression for "BLOB/TEXT column 'info' can't have a default value") # on MySQL. |
