summaryrefslogtreecommitdiff
path: root/django
diff options
context:
space:
mode:
authorMarkus Holtermann <info@markusholtermann.eu>2014-11-30 18:11:52 +0100
committerTim Graham <timograham@gmail.com>2014-12-01 16:00:36 -0500
commitba3e97618696bdd68e4ac9b2220f58e6b3d15bd4 (patch)
tree8af8d662735f4353e2f1af23b381435e3d7445bd /django
parentd62e16fe46684f86dada90fb615651686945263d (diff)
[1.7.x] Fixed #23880 -- Added missing index_together handling for SQLite
Backport of d2202ec2d4d0477b682c6d0051f27ab4843ef89f from master
Diffstat (limited to 'django')
-rw-r--r--django/db/backends/sqlite3/schema.py20
1 files changed, 19 insertions, 1 deletions
diff --git a/django/db/backends/sqlite3/schema.py b/django/db/backends/sqlite3/schema.py
index 7ed5449c8d..ef9bda9368 100644
--- a/django/db/backends/sqlite3/schema.py
+++ b/django/db/backends/sqlite3/schema.py
@@ -43,7 +43,8 @@ class DatabaseSchemaEditor(BaseDatabaseSchemaEditor):
else:
raise ValueError("Cannot quote parameter value %r of type %s" % (value, type(value)))
- def _remake_table(self, model, create_fields=[], delete_fields=[], alter_fields=[], override_uniques=None):
+ def _remake_table(self, model, create_fields=[], delete_fields=[], alter_fields=[], override_uniques=None,
+ override_indexes=None):
"""
Shortcut to transform a model from old_model into new_model
"""
@@ -110,11 +111,20 @@ class DatabaseSchemaEditor(BaseDatabaseSchemaEditor):
for unique in model._meta.unique_together
]
+ # Work out the new value for index_together, taking renames into
+ # account
+ if override_indexes is None:
+ override_indexes = [
+ [rename_mapping.get(n, n) for n in index]
+ for index in model._meta.index_together
+ ]
+
# Construct a new model for the new state
meta_contents = {
'app_label': model._meta.app_label,
'db_table': model._meta.db_table + "__new",
'unique_together': override_uniques,
+ 'index_together': override_indexes,
'apps': apps,
}
meta = type("Meta", tuple(), meta_contents)
@@ -189,6 +199,14 @@ class DatabaseSchemaEditor(BaseDatabaseSchemaEditor):
# Alter by remaking table
self._remake_table(model, alter_fields=[(old_field, new_field)])
+ def alter_index_together(self, model, old_index_together, new_index_together):
+ """
+ Deals with a model changing its index_together.
+ Note: The input index_togethers must be doubly-nested, not the single-
+ nested ["foo", "bar"] format.
+ """
+ self._remake_table(model, override_indexes=new_index_together)
+
def alter_unique_together(self, model, old_unique_together, new_unique_together):
"""
Deals with a model changing its unique_together.