1
0
mirror of https://github.com/django/django.git synced 2025-10-24 06:06:09 +00:00

Fixed #28668 -- Allowed QuerySet.bulk_create() to ignore insert conflicts.

This commit is contained in:
Tom
2017-10-03 00:35:38 +01:00
committed by Tim Graham
parent 45086c294d
commit f1fbef6cd1
13 changed files with 105 additions and 14 deletions

View File

@@ -2039,7 +2039,7 @@ exists in the database, an :exc:`~django.db.IntegrityError` is raised.
``bulk_create()``
~~~~~~~~~~~~~~~~~
.. method:: bulk_create(objs, batch_size=None)
.. method:: bulk_create(objs, batch_size=None, ignore_conflicts=False)
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
@@ -2079,6 +2079,16 @@ The ``batch_size`` parameter controls how many objects are created in a single
query. The default is to create all objects in one batch, except for SQLite
where the default is such that at most 999 variables per query are used.
On databases that support it (all except PostgreSQL < 9.5 and 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).
.. versionchanged:: 2.2
The ``ignore_conflicts`` parameter was added.
``count()``
~~~~~~~~~~~