diff options
| author | Andrew Godwin <andrew@aeracode.org> | 2013-08-11 14:23:31 +0100 |
|---|---|---|
| committer | Andrew Godwin <andrew@aeracode.org> | 2013-08-11 14:23:31 +0100 |
| commit | ae19315b4d8a19eda07ea8f313c485ca0a7875d0 (patch) | |
| tree | 596f9d8d139968d65b30dafec67067a015ed3ac6 /tests | |
| parent | 21be9fef7b14edd75c6ee402ec2bb28bf9b6ce59 (diff) | |
Support index_together during model creation
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/schema/models.py | 9 | ||||
| -rw-r--r-- | tests/schema/tests.py | 19 |
2 files changed, 27 insertions, 1 deletions
diff --git a/tests/schema/models.py b/tests/schema/models.py index a160b9aaa8..69cf06f3c4 100644 --- a/tests/schema/models.py +++ b/tests/schema/models.py @@ -62,6 +62,15 @@ class Tag(models.Model): app_cache = new_app_cache +class TagIndexed(models.Model): + title = models.CharField(max_length=255) + slug = models.SlugField(unique=True) + + class Meta: + app_cache = new_app_cache + index_together = [["slug", "title"]] + + class TagUniqueRename(models.Model): title = models.CharField(max_length=255) slug2 = models.SlugField(unique=True) diff --git a/tests/schema/tests.py b/tests/schema/tests.py index 3a82cd15ff..f6e45599b8 100644 --- a/tests/schema/tests.py +++ b/tests/schema/tests.py @@ -6,7 +6,7 @@ from django.db import connection, DatabaseError, IntegrityError from django.db.models.fields import IntegerField, TextField, CharField, SlugField from django.db.models.fields.related import ManyToManyField, ForeignKey from django.db.transaction import atomic -from .models import Author, AuthorWithM2M, Book, BookWithSlug, BookWithM2M, Tag, TagUniqueRename, UniqueTest +from .models import Author, AuthorWithM2M, Book, BookWithSlug, BookWithM2M, Tag, TagIndexed, TagUniqueRename, UniqueTest class SchemaTests(TransactionTestCase): @@ -503,6 +503,23 @@ class SchemaTests(TransactionTestCase): ), ) + def test_create_index_together(self): + """ + Tests creating models with index_together already defined + """ + # Create the table + with connection.schema_editor() as editor: + editor.create_model(TagIndexed) + # Ensure there is an index + self.assertEqual( + True, + any( + c["index"] + for c in connection.introspection.get_constraints(connection.cursor(), "schema_tagindexed").values() + if c['columns'] == ["slug", "title"] + ), + ) + def test_db_table(self): """ Tests renaming of the table |
