pythondjangodjango-import-export

django-import-export: cannot exclude id field during import : KeyError: u'id'


On Django-1.9.6, django-import-export-0.5

When I try to upload CSV without "id" field throws this error.

Line number: 1 - u'id'
13173474, Harry McDade, 10.harry.asas@asasasas.com
Traceback (most recent call last):
File "/Users/isanka/dev/venv/edxubase/lib/python2.7/site-packages/import_export/resources.py", line 434, in import_row
instance, new = self.get_or_init_instance(instance_loader, row)
File "/Users/isanka/dev/venv/edxubase/lib/python2.7/site-packages/import_export/resources.py", line 258, in get_or_init_instance
instance = self.get_instance(instance_loader, row)
File "/Users/isanka/dev/venv/edxubase/lib/python2.7/site-packages/import_export/resources.py", line 252, in get_instance
return instance_loader.get_instance(row)
File "/Users/isanka/dev/venv/edxubase/lib/python2.7/site-packages/import_export/instance_loaders.py", line 31, in get_instance
field = self.resource.fields[key]
KeyError: u'id'

Solution

  • Seems "django-import-export" still using the default one 'id'. for the time been, included a column 'id' in the header in CSV file and excluded importing in resources.py

    class edxUserResource(resources.ModelResource):
    
        class Meta:
            model = edxUser
            skip_unchanged = True
            report_skipped = True
            exclude = ('id',)
            import_id_fields = ('edx_id', 'edx_email', 'edx_name',)
            #export_order = ('edx_id', 'edx_email')