Couldn't able to exclude the ID, even tried with the existing question in stackoverflow:
django-import-export: cannot exclude id field during import : KeyError: u'id'
resource.py
from import_export import resources
from .models import Bugdata
class BugDataResource(resources.ModelResource):
class Meta:
model = Bugdata
skip_unchanged = True
report_skipped = True
exclude = ('id',)
import_id_fields = ['Created_date', 'BugID', 'ID_Link', 'Summary', 'Status', 'Severity', 'Tags']
models.py
from django.db import models
class Bugdata(models.Model):
Created_date = models.DateField()
BugID = models.CharField(max_length=50,primary_key=True)
ID_Link = models.URLField(max_length=300)
Summary = models.CharField(max_length=600)
Status = models.CharField(max_length=10)
Severity = models.CharField(max_length=10)
Tags = models.CharField(max_length=10)
def __str__(self):
return self.Summary
admin.py
from django.contrib import admin
from import_export.admin import ImportExportModelAdmin
from .models import Bugdata
# Register your models here.
@admin.register(Bugdata)
class NewtaskAdmin(ImportExportModelAdmin):
Traceback
Error:
Traceback (most recent call last):
File "C:\Users\gomathis\AppData\Local\Programs\Python\Python36-32\lib\site-
packages\django_import_export-1.0.1-py3.6.egg\import_export\resources.py",
line 453, in import_row
instance, new = self.get_or_init_instance(instance_loader, row)
File "C:\Users\gomathis\AppData\Local\Programs\Python\Python36-32\lib\site-
packages\django_import_export-1.0.1-py3.6.egg\import_export\resources.py",
line 267, in get_or_init_instance
instance = self.get_instance(instance_loader, row)
File "C:\Users\gomathis\AppData\Local\Programs\Python\Python36-32\lib\site-
packages\django_import_export-1.0.1-py3.6.egg\import_export\resources.py",
line 261, in get_instance
return instance_loader.get_instance(row)
File "C:\Users\gomathis\AppData\Local\Programs\Python\Python36-32\lib\site-
packages\django_import_export-1.0.1-
py3.6.egg\import_export\instance_loaders.py", line 31, in get_instance
field = self.resource.fields[key]
KeyError: 'id'
Apparently I don't have the reputation to add a comment, did you resolve this? I was having something similar occur with the same setup as yourself, so one suggestion is to double check the encoding of the file you are impording. I have had issues with Excel on a Mac saving to CSV format, in this case I used a text editor such as sublime to make sure it's saved to UTF8 format and that particular error seemed to disappear.
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
site design / logo © 2020 Stack Exchange Inc; user contributions licensed under cc by-sa 4.0
with attribution required.
rev 2020.3.11.36249