diff options
Diffstat (limited to 'docs')
| -rw-r--r-- | docs/ref/models/querysets.txt | 22 | ||||
| -rw-r--r-- | docs/releases/4.1.txt | 12 |
2 files changed, 30 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()`` ~~~~~~~~~~~~~~~~~ diff --git a/docs/releases/4.1.txt b/docs/releases/4.1.txt index b6112fe29e..8fc23e6141 100644 --- a/docs/releases/4.1.txt +++ b/docs/releases/4.1.txt @@ -232,6 +232,10 @@ Models in order to reduce the number of failed requests, e.g. after database server restart. +* :meth:`.QuerySet.bulk_create` now supports updating fields when a row + insertion fails uniqueness constraints. This is supported on MariaDB, MySQL, + PostgreSQL, and SQLite 3.24+. + Requests and Responses ~~~~~~~~~~~~~~~~~~~~~~ @@ -298,6 +302,14 @@ backends. * ``DatabaseIntrospection.get_key_columns()`` is removed. Use ``DatabaseIntrospection.get_relations()`` instead. +* ``DatabaseOperations.ignore_conflicts_suffix_sql()`` method is replaced by + ``DatabaseOperations.on_conflict_suffix_sql()`` that accepts the ``fields``, + ``on_conflict``, ``update_fields``, and ``unique_fields`` arguments. + +* The ``ignore_conflicts`` argument of the + ``DatabaseOperations.insert_statement()`` method is replaced by + ``on_conflict`` that accepts ``django.db.models.constants.OnConflict``. + Dropped support for MariaDB 10.2 -------------------------------- |
