                                          objects_in_fixture += 1
                                          if router.allow_syncdb(using, obj.object.__class__):
                                              loaded_objects_in_fixture += 1
                                              models.add(obj.object.__class__)
                                              obj.save(using=using)
  
                                  # Since we disabled constraint checks, we must manually check for
                                  # any invalid keys that might have been added
                                  table_names = [model._meta.db_table for model in models]
                                  connection.check_constraints(table_names=table_names)
 
</s> remove from django.db import connections, router, transaction, DEFAULT_DB_ALIAS
 </s> add from django.db import (connections, router, transaction, DEFAULT_DB_ALIAS,
      IntegrityError, DatabaseError)
                                            try:
                                                obj.save(using=using)
                                            except (DatabaseError, IntegrityError), e:
                                                msg = "Could not load %(app_label)s.%(object_name)s(pk=%(pk)s): %(error_msg)s" % {
                                                        'app_label': obj.object._meta.app_label,
                                                        'object_name': obj.object._meta.object_name,
                                                        'pk': obj.object.pk,
                                                        'error_msg': e
                                                    }
                                                raise e.__class__, e.__class__(msg), sys.exc_info()[2]
                                          objects_in_fixture += 1
                                          if router.allow_syncdb(using, obj.object.__class__):
                                              loaded_objects_in_fixture += 1
                                              models.add(obj.object.__class__)
                                            try:
                                                obj.save(using=using)
                                            except (DatabaseError, IntegrityError), e:
                                                msg = "Could not load %(app_label)s.%(object_name)s(pk=%(pk)s): %(error_msg)s" % {
                                                        'app_label': obj.object._meta.app_label,
                                                        'object_name': obj.object._meta.object_name,
                                                        'pk': obj.object.pk,
                                                        'error_msg': e
                                                    }
                                                raise e.__class__, e.__class__(msg), sys.exc_info()[2]
  
                                  # Since we disabled constraint checks, we must manually check for
                                  # any invalid keys that might have been added
                                  table_names = [model._meta.db_table for model in models]
                                  connection.check_constraints(table_names=table_names)
keep keep keep keep replace keep keep keep keep keep
 Fixed #16026 -- loaddata now identifies which object triggered an error.


git-svn-id: http://code.djangoproject.com/svn/django/trunk@16873 bcc190cf-cafb-0310-a4f2-bffc1f526a37 
django/core/management/commands/loaddata.py