mirror of
https://github.com/django/django.git
synced 2025-10-25 22:56:12 +00:00
[1.8.x] Fixed #24972 -- Fixed removing unique_together indexes on MySQL.
Backport of 65296b3be3 from master
This commit is contained in:
committed by
Tim Graham
parent
c58755d875
commit
0e3a80fa68
@@ -20,8 +20,9 @@ from django.test import TransactionTestCase, skipIfDBFeature
|
||||
from .fields import CustomManyToManyField, InheritedManyToManyField
|
||||
from .models import (
|
||||
Author, AuthorWithDefaultHeight, AuthorWithEvenLongerName, Book, BookWeak,
|
||||
BookWithLongName, BookWithO2O, BookWithSlug, IntegerPK, Note, NoteRename,
|
||||
Tag, TagIndexed, TagM2MTest, TagUniqueRename, Thing, UniqueTest, new_apps,
|
||||
BookWithLongName, BookWithO2O, BookWithoutAuthor, BookWithSlug, IntegerPK,
|
||||
Note, NoteRename, Tag, TagIndexed, TagM2MTest, TagUniqueRename, Thing,
|
||||
UniqueTest, new_apps,
|
||||
)
|
||||
|
||||
|
||||
@@ -1185,6 +1186,28 @@ class SchemaTests(TransactionTestCase):
|
||||
with connection.schema_editor() as editor:
|
||||
editor.alter_unique_together(Book, [['author', 'title']], [])
|
||||
|
||||
def test_unique_together_with_fk_with_existing_index(self):
|
||||
"""
|
||||
Tests removing and adding unique_together constraints that include
|
||||
a foreign key, where the foreign key is added after the model is
|
||||
created.
|
||||
"""
|
||||
# Create the tables
|
||||
with connection.schema_editor() as editor:
|
||||
editor.create_model(Author)
|
||||
editor.create_model(BookWithoutAuthor)
|
||||
new_field = ForeignKey(Author)
|
||||
new_field.set_attributes_from_name('author')
|
||||
editor.add_field(BookWithoutAuthor, new_field)
|
||||
# Ensure the fields aren't unique to begin with
|
||||
self.assertEqual(Book._meta.unique_together, ())
|
||||
# Add the unique_together constraint
|
||||
with connection.schema_editor() as editor:
|
||||
editor.alter_unique_together(Book, [], [['author', 'title']])
|
||||
# Alter it back
|
||||
with connection.schema_editor() as editor:
|
||||
editor.alter_unique_together(Book, [['author', 'title']], [])
|
||||
|
||||
def test_index_together(self):
|
||||
"""
|
||||
Tests removing and adding index_together constraints on a model.
|
||||
|
||||
Reference in New Issue
Block a user