summaryrefslogtreecommitdiff
path: root/django/core/management.py
diff options
context:
space:
mode:
authorRussell Keith-Magee <russell@keith-magee.com>2006-10-03 13:46:11 +0000
committerRussell Keith-Magee <russell@keith-magee.com>2006-10-03 13:46:11 +0000
commitf5087775b365906adeb25b66d1a6b8f1034c9e67 (patch)
tree7608cdbafac0117ee0f54145f8a125d910f6cc62 /django/core/management.py
parentb08a8dbb6569b0dac5d14320f3d7eee863d6fcc9 (diff)
Refs #1828 -- Added creation of indexes as a step in syncdb. This is an interim solution; the long term solution requires a non-trivial refactoring of syncdb, install and the get_* calls in management.py. Thanks to mdt@emdete.de for the original report, and to Simon Greenhill for prodding me to an interim fix.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@3893 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django/core/management.py')
-rw-r--r--django/core/management.py19
1 files changed, 19 insertions, 0 deletions
diff --git a/django/core/management.py b/django/core/management.py
index c6ab34f040..1f2869addc 100644
--- a/django/core/management.py
+++ b/django/core/management.py
@@ -521,6 +521,25 @@ def syncdb(verbosity=1, interactive=True):
transaction.rollback_unless_managed()
else:
transaction.commit_unless_managed()
+
+ # Install SQL indicies for all newly created models
+ for app in models.get_apps():
+ app_name = app.__name__.split('.')[-2]
+ for model in models.get_models(app):
+ if model in created_models:
+ index_sql = _get_sql_index(model)
+ if index_sql:
+ if verbosity >= 1:
+ print "Installing index for %s.%s model" % (app_name, model._meta.object_name)
+ try:
+ for sql in index_sql:
+ cursor.execute(sql)
+ except Exception, e:
+ sys.stderr.write("Failed to install index for %s.%s model: %s" % \
+ (app_name, model._meta.object_name, e))
+ transaction.rollback_unless_managed()
+ else:
+ transaction.commit_unless_managed()
syncdb.args = ''