Model is imported with empty pk value
See original GitHub issueDescribe the bug I try to import a csv file via django admin with only one column which is also the primary key field for that model. The csv consist of 3 columns but only the first one is of any interest here. The import seems to work as I get a success message but if I look at the list view in django admin there is only one more entry with an empty key field.
To Reproduce Steps to reproduce the behavior: Prerequisite is the following model:
class Token(models.Model):
key = models.CharField(db_index=True,unique=True,primary_key=True, )
state = models.PositiveSmallIntegerField(default=State.VALID, choices=State.choices)
then
class TokenResource(resources.ModelResource):
class Meta:
model = Token
report_skipped = True
import_id_fields = ("key",)
fields = ("key",)
the django Admin entry:
class TokenAdmin(ImportMixin, admin.ModelAdmin):
resource_class = TokenResource
and some csv: key;type;number ABCDEFG;Publication;101549 GFEDCBA;Publication;101549
then go to this model in django admin list view and click import. Choose file with sample data, csv and click import.
On the preview you get table with
After clicking import you get the success message:
Versions (please complete the following information):
- Django Import Export: 2.7.0
- Python 3.9
- Django 3.2
Expected behavior A list with the imported Tokens should appear within the list view, with a filled key value
Details import_export.resources.ModelResource.init_instance --> return self._meta.model() returns an instance without a key although the key value has been passed with the row
Issue Analytics
- State:
- Created 2 years ago
- Comments:6 (3 by maintainers)
Ok thanks, must have overlooked that. I cannot change this somewhere in the settings, right? So I will adapt the file.
OK thanks - your issue is a simple one - you are using ‘;’ as the delimiter in your csv. If you change this to ‘,’ it will work:
If you need to use semi-colon as the delimiter, there are instructions here.