Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Test that unique constraints get ported with column rename

  • Loading branch information...
commit 0b013951086814ebee048f0fa9a620e03f891494 1 parent f7955c7
@andrewgodwin andrewgodwin authored
View
9 tests/modeltests/schema/models.py
@@ -37,6 +37,15 @@ class Meta:
managed = False
+class TagUniqueRename(models.Model):
+ title = models.CharField(max_length=255)
+ slug2 = models.SlugField(unique=True)
+
+ class Meta:
+ managed = False
+ db_table = "schema_tag"
+
+
class UniqueTest(models.Model):
year = models.IntegerField()
slug = models.SlugField(unique=False)
View
17 tests/modeltests/schema/tests.py
@@ -6,7 +6,7 @@
from django.db.models.fields import IntegerField, TextField, CharField, SlugField
from django.db.models.fields.related import ManyToManyField
from django.db.models.loading import cache
-from .models import Author, Book, AuthorWithM2M, Tag, UniqueTest
+from .models import Author, Book, AuthorWithM2M, Tag, TagUniqueRename, UniqueTest
class SchemaTests(TestCase):
@@ -297,6 +297,21 @@ def test_unique(self):
Tag.objects.create(title="foo", slug="foo")
self.assertRaises(IntegrityError, Tag.objects.create, title="bar", slug="foo")
connection.rollback()
+ # Rename the field
+ new_field = SlugField(unique=False)
+ new_field.set_attributes_from_name("slug2")
+ editor = connection.schema_editor()
+ editor.start()
+ editor.alter_field(
+ Tag,
+ Tag._meta.get_field_by_name("slug")[0],
+ TagUniqueRename._meta.get_field_by_name("slug2")[0],
+ )
+ editor.commit()
+ # Ensure the field is still unique
+ TagUniqueRename.objects.create(title="foo", slug2="foo")
+ self.assertRaises(IntegrityError, TagUniqueRename.objects.create, title="bar", slug2="foo")
+ connection.rollback()
def test_unique_together(self):
"""

0 comments on commit 0b01395

Please sign in to comment.
Something went wrong with that request. Please try again.