1
0
mirror of https://github.com/django/django.git synced 2025-10-24 06:06:09 +00:00

Support index_together during model creation

This commit is contained in:
Andrew Godwin
2013-08-11 14:23:31 +01:00
parent 21be9fef7b
commit ae19315b4d
4 changed files with 40 additions and 2 deletions

View File

@@ -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