Wasting Primary Key ID's
See original GitHub issueIn case if you try to import a CSV file using ImportExportModelAdmin
say I have a Django modes named PRODUCTS
as:
product_id (pk) name (char) size (char) etc...
1 milk 500ml
2 bread Large
admin.py
looks like:
class ProductAdmin(ImportExportModelAdmin):
resource_class = ProductResource
admin.site.register(Product, ProductAdmin)
resource.py
that holds ProductResouces
class look like:
class ProductResource(resources.ModelResource):
class Meta:
model = Product
import_id_fields = ['product_id']
skip_unchanged = True
report_skipped = True
use_transactions = True
and the issue is with uploading CSV file without product_id
:
the CSV file looks like:
product_id (pk) name (char) size (char) etc...
fresh milk 500ml
Note: Here I haven’t passed the product_id
.
So when I do import from my Django admin, it shows data as:
product_id (pk) name (char) size (char) etc...
3 fresh milk 500ml
Probably it get this primary key returned from database (MYSQL) and then shows confirm import button on chick of which the record I have is:
4 fresh milk 500ml
the id imported is 4 rather than 3.
I have
IMPORT_EXPORT_USE_TRANSACTIONS = True in settings.py
also have tried to make use_transactiosn = False
in both settings.py
and in resources.py
and alternative combinations, still it wastes 1
primary key id
in database whenever I don’t pass a primary key in my csv file
Issue Analytics
- State:
- Created 5 years ago
- Comments:5 (2 by maintainers)
Relevant bit of text here from #560 :
Please see https://github.com/django-import-export/django-import-export/issues/560#issuecomment-270673979