Allow QuerySet.bulk_create() to set the primary key of its objects
|Reported by:||Vlada Macek||Owned by:||nobody|
|Component:||Database layer (models, ORM)||Version:||master|
|Cc:||charette.s@…, gwahl@…, w2lkm2n@…, mszamot@…, AkosLadanyi, Shai Berger, acrefoot@…, benth, dev@…||Triage Stage:||Accepted|
|Has patch:||no||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
(Sorry if I missed a pre-existing ticket for this.)
There is an IMO big caveat of bulk_create(): It does not set primary key of objects it creates.
In my current project, using bulk_create would improve performance, but as I often need an id of the newly created objects, I have to save them one by one.
I think it would be perfect if bulk_create starts to set the primary keys of the objects in the given sequence. At least postgresql supports it ("RETURNING id" clause gives us a set of id's).
Change History (47)
comment:23 Changed 21 months ago by
|Summary:||bulk_create() can set the primary key → Allow QuerySet.bulk_create() to set the primary key of its objects|