diff options
| author | sean_c_hsu <s8901489@gmail.com> | 2020-06-15 00:58:06 +0800 |
|---|---|---|
| committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2022-01-19 20:17:42 +0100 |
| commit | 0f6946495a8ec955b471ca1baaf408ceb53d4796 (patch) | |
| tree | c3d867d141074fb990d3140e02fbaa9d717e8ff2 /docs/ref | |
| parent | ba9de2e74edb155067dc96a3369305c9ef4ba385 (diff) | |
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.
Diffstat (limited to 'docs/ref')
| -rw-r--r-- | docs/ref/models/querysets.txt | 22 |
1 files changed, 18 insertions, 4 deletions
diff --git a/docs/ref/models/querysets.txt b/docs/ref/models/querysets.txt index e0d4311b15..60360ee163 100644 --- a/docs/ref/models/querysets.txt +++ b/docs/ref/models/querysets.txt @@ -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()`` ~~~~~~~~~~~~~~~~~ |
