mirror of
https://github.com/django/django.git
synced 2025-08-04 10:59:45 +00:00
Fixed #31685 -- Added support for updating conflicts to QuerySet.bulk_create().
Thanks Florian Apolloner, Chris Jerdonek, Hannes Ljungberg, Nick Pope, and Mariusz Felisiak for reviews.
This commit is contained in:
parent
ba9de2e74e
commit
0f6946495a
16 changed files with 542 additions and 43 deletions
|
@ -2155,7 +2155,7 @@ exists in the database, an :exc:`~django.db.IntegrityError` is raised.
|
|||
``bulk_create()``
|
||||
~~~~~~~~~~~~~~~~~
|
||||
|
||||
.. method:: bulk_create(objs, batch_size=None, ignore_conflicts=False)
|
||||
.. method:: bulk_create(objs, batch_size=None, ignore_conflicts=False, update_conflicts=False, update_fields=None, unique_fields=None)
|
||||
|
||||
This method inserts the provided list of objects into the database in an
|
||||
efficient manner (generally only 1 query, no matter how many objects there
|
||||
|
@ -2198,9 +2198,17 @@ where the default is such that at most 999 variables per query are used.
|
|||
|
||||
On databases that support it (all but Oracle), setting the ``ignore_conflicts``
|
||||
parameter to ``True`` tells the database to ignore failure to insert any rows
|
||||
that fail constraints such as duplicate unique values. Enabling this parameter
|
||||
disables setting the primary key on each model instance (if the database
|
||||
normally supports it).
|
||||
that fail constraints such as duplicate unique values.
|
||||
|
||||
On databases that support it (all except Oracle and SQLite < 3.24), setting the
|
||||
``update_conflicts`` parameter to ``True``, tells the database to update
|
||||
``update_fields`` when a row insertion fails on conflicts. On PostgreSQL and
|
||||
SQLite, in addition to ``update_fields``, a list of ``unique_fields`` that may
|
||||
be in conflict must be provided.
|
||||
|
||||
Enabling the ``ignore_conflicts`` or ``update_conflicts`` parameter disable
|
||||
setting the primary key on each model instance (if the database normally
|
||||
support it).
|
||||
|
||||
.. warning::
|
||||
|
||||
|
@ -2217,6 +2225,12 @@ normally supports it).
|
|||
|
||||
Support for the fetching primary key attributes on SQLite 3.35+ was added.
|
||||
|
||||
.. versionchanged:: 4.1
|
||||
|
||||
The ``update_conflicts``, ``update_fields``, and ``unique_fields``
|
||||
parameters were added to support updating fields when a row insertion fails
|
||||
on conflict.
|
||||
|
||||
``bulk_update()``
|
||||
~~~~~~~~~~~~~~~~~
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue