                          with transaction.commit_on_success_unless_managed(using=db):
                              try:
                                  for sql in index_sql:
                                      cursor.execute(sql)
                              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
  
          # Load initial_data fixtures (unless that has been disabled)
          if load_initial_data:
              call_command('loaddata', 'initial_data', verbosity=verbosity,
                           database=db, skip_validation=True)
 
</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): </s> remove                             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
 </s> add                         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 index for %s.%s model: %s\n" % \
                                                (app_name, model._meta.object_name, e))
                          with transaction.commit_on_success_unless_managed(using=db):
                              try:
                                  for sql in index_sql:
                                      cursor.execute(sql)
                        except Exception as e:
                            self.stderr.write("Failed to install index for %s.%s model: %s\n" % \
                                                (app_name, model._meta.object_name, e))
                        except Exception as e:
                            self.stderr.write("Failed to install index for %s.%s model: %s\n" % \
                                                (app_name, model._meta.object_name, e))
                        except Exception as e:
                            self.stderr.write("Failed to install index for %s.%s model: %s\n" % \
                                                (app_name, model._meta.object_name, e))
                        except Exception as e:
                            self.stderr.write("Failed to install index for %s.%s model: %s\n" % \
                                                (app_name, model._meta.object_name, e))
  
          # Load initial_data fixtures (unless that has been disabled)
          if load_initial_data:
              call_command('loaddata', 'initial_data', verbosity=verbosity,
                           database=db, skip_validation=True)
keep keep keep keep 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