summaryrefslogtreecommitdiff
path: root/django
diff options
context:
space:
mode:
authorAndrew Godwin <andrew@aeracode.org>2013-08-11 14:23:31 +0100
committerAndrew Godwin <andrew@aeracode.org>2013-08-11 14:23:31 +0100
commitae19315b4d8a19eda07ea8f313c485ca0a7875d0 (patch)
tree596f9d8d139968d65b30dafec67067a015ed3ac6 /django
parent21be9fef7b14edd75c6ee402ec2bb28bf9b6ce59 (diff)
Support index_together during model creation
Diffstat (limited to 'django')
-rw-r--r--django/db/backends/schema.py9
-rw-r--r--django/db/backends/sqlite3/introspection.py5
2 files changed, 13 insertions, 1 deletions
diff --git a/django/db/backends/schema.py b/django/db/backends/schema.py
index 1e1376a4e2..d868bf79b5 100644
--- a/django/db/backends/schema.py
+++ b/django/db/backends/schema.py
@@ -210,6 +210,15 @@ class BaseDatabaseSchemaEditor(object):
"definition": ", ".join(column_sqls)
}
self.execute(sql, params)
+ # Add any index_togethers
+ for fields in model._meta.index_together:
+ columns = [model._meta.get_field_by_name(field)[0].column for field in fields]
+ self.execute(self.sql_create_index % {
+ "table": self.quote_name(model._meta.db_table),
+ "name": self._create_index_name(model, columns, suffix="_idx"),
+ "columns": ", ".join(self.quote_name(column) for column in columns),
+ "extra": "",
+ })
# Make M2M tables
for field in model._meta.local_many_to_many:
self.create_model(field.rel.through)
diff --git a/django/db/backends/sqlite3/introspection.py b/django/db/backends/sqlite3/introspection.py
index 2e674bc05b..92777dd910 100644
--- a/django/db/backends/sqlite3/introspection.py
+++ b/django/db/backends/sqlite3/introspection.py
@@ -168,7 +168,10 @@ class DatabaseIntrospection(BaseDatabaseIntrospection):
"""
# Don't use PRAGMA because that causes issues with some transactions
cursor.execute("SELECT sql FROM sqlite_master WHERE tbl_name = %s AND type = %s", [table_name, "table"])
- results = cursor.fetchone()[0].strip()
+ row = cursor.fetchone()
+ if row is None:
+ raise ValueError("Table %s does not exist" % table_name)
+ results = row[0].strip()
results = results[results.index('(') + 1:results.rindex(')')]
for field_desc in results.split(','):
field_desc = field_desc.strip()