Allow QuerySet.bulk_create() to set the primary key of its objects
|Reported by:||Tuttle||Owned by:||nobody|
|Component:||Database layer (models, ORM)||Version:||master|
|Cc:||charette.s@…, gwahl@…, w2lkm2n@…, mszamot@…, AkosLadanyi, shai, 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 (43)
comment:1 Changed 4 years ago by akaariai
- Needs documentation unset
- Needs tests unset
- Patch needs improvement unset
comment:3 Changed 4 years ago by aaugustin
- Triage Stage changed from Unreviewed to Design decision needed
comment:9 Changed 3 years ago by aaugustin
- Triage Stage changed from Design decision needed to Accepted
comment:23 Changed 12 months ago by timgraham
- Keywords QuerySet.bulk_create added
- Summary changed from bulk_create() can set the primary key to Allow QuerySet.bulk_create() to set the primary key of its objects