                          with transaction.commit_on_success_unless_managed(using=db):
                              try:
                                  for sql in custom_sql:
                                      cursor.execute(sql)
                              except Exception as e:
                                  self.stderr.write("Failed to install custom SQL for %s.%s model: %s\n" % \
                                                      (app_name, model._meta.object_name, e))
                                  if show_traceback:
                                      traceback.print_exc()
                                  raise
                      else:
                          if verbosity >= 3:
                              self.stdout.write("No custom SQL for %s.%s model\n" % (app_name, model._meta.object_name))
  
          if verbosity >= 1:
 
</s> remove                             except Exception as e:
                                self.stderr.write("Failed to install index for %s.%s model: %s\n" % \
                                                    (app_name, model._meta.object_name, e))
                                raise
 </s> add                         except Exception as e:
                            self.stderr.write("Failed to install index for %s.%s model: %s\n" % \
                                                (app_name, model._meta.object_name, e)) </s> remove                         with transaction.commit_on_success_unless_managed(using=db):
                            try:
 </s> add                         try:
                            with transaction.commit_on_success_unless_managed(using=db): </s> remove                         with transaction.commit_on_success_unless_managed(using=db):
                            try:
 </s> add                         try:
                            with transaction.commit_on_success_unless_managed(using=db):
                        except Exception as e:
                            self.stderr.write("Failed to install custom SQL for %s.%s model: %s\n" % \
                                                (app_name, model._meta.object_name, e))
                            if show_traceback:
                                traceback.print_exc()
                          with transaction.commit_on_success_unless_managed(using=db):
                              try:
                                  for sql in custom_sql:
                                      cursor.execute(sql)
                        except Exception as e:
                            self.stderr.write("Failed to install custom SQL for %s.%s model: %s\n" % \
                                                (app_name, model._meta.object_name, e))
                            if show_traceback:
                                traceback.print_exc()
                        except Exception as e:
                            self.stderr.write("Failed to install custom SQL for %s.%s model: %s\n" % \
                                                (app_name, model._meta.object_name, e))
                            if show_traceback:
                                traceback.print_exc()
                        except Exception as e:
                            self.stderr.write("Failed to install custom SQL for %s.%s model: %s\n" % \
                                                (app_name, model._meta.object_name, e))
                            if show_traceback:
                                traceback.print_exc()
                        except Exception as e:
                            self.stderr.write("Failed to install custom SQL for %s.%s model: %s\n" % \
                                                (app_name, model._meta.object_name, e))
                            if show_traceback:
                                traceback.print_exc()
                        except Exception as e:
                            self.stderr.write("Failed to install custom SQL for %s.%s model: %s\n" % \
                                                (app_name, model._meta.object_name, e))
                            if show_traceback:
                                traceback.print_exc()
                        except Exception as e:
                            self.stderr.write("Failed to install custom SQL for %s.%s model: %s\n" % \
                                                (app_name, model._meta.object_name, e))
                            if show_traceback:
                                traceback.print_exc()
                      else:
                          if verbosity >= 3:
                              self.stdout.write("No custom SQL for %s.%s model\n" % (app_name, model._meta.object_name))
  
          if verbosity >= 1:
keep keep keep keep replace replace replace replace replace replace keep keep keep keep keep
 Fixed a refactoring error in ba5138b1.

Thanks Florian for tracing the error. 
django/core/management/commands/syncdb.py