From f5087775b365906adeb25b66d1a6b8f1034c9e67 Mon Sep 17 00:00:00 2001 From: Russell Keith-Magee Date: Tue, 3 Oct 2006 13:46:11 +0000 Subject: [PATCH] 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 --- django/core/management.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) 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 = ''