Search code examples
djangodjango-import-export

Import wants to override unchanged fields


If i export to xlsx and reimport, Django-Import-Export reports overwritten fields but there are no changes. I already tried to debug this myself with the skip_row() method but i think im generally doing sommething wrong

resources.py

class FormatClassResource(resources.ModelResource):
    number = fields.Field(column_name="Nummer", attribute="number")
    barcode = fields.Field(column_name="Barcode", attribute="barcode")
    name = fields.Field(column_name="Name", attribute="name")
    price = fields.Field(column_name="Preis", attribute="price")

    class Meta:
        model = FormatClass
        use_bulk = True
        use_transactions = True
        skip_unchanged = True
        import_id_fields = ["number", "barcode", "name", "price"]
        exclude = ["id"]

Import result


Solution

  • Some points which may help:

    • The import process is going to try to load existing data based on all four attributes in import_id_fields
    • It will then compare all fields from your Excel file (which correspond to attributes in FormatClass) with what is persisted, and if any of them do not match, it will report an 'update'
    • Set a breakpoint here to catch which field it thinks has changed.