Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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
  • Loading branch information...
commit f5087775b365906adeb25b66d1a6b8f1034c9e67 1 parent b08a8db
Russell Keith-Magee freakboy3742 authored
Showing with 19 additions and 0 deletions.
  1. +19 −0 django/core/management.py
19 django/core/management.py
View
@@ -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 = ''
Please sign in to comment.
Something went wrong with that request. Please try again.