10π
As of Django 2.2, bulk_create has an ignore_conflicts
flag. Per the docs:
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
5π
This post may be of use to you:
stackoverflow.com/questions/3395236/aggregating-saves-in-django
Note that the answer recommends using the commit_on_success decorator which is deprecated. It is replaced by the transaction.atomic decorator. Documentation is here:
from django.db import transaction
@transaction.atomic
def lot_of_saves(queryset):
for item in queryset:
modify_item(item)
item.save()
- [Django]-Create a field whose value is a calculation of other fields' values
- [Django]-Django 1.7 β App 'your_app_name' does not have migrations
- [Django]-How to pass django rest framework response to html?
2π
If I understand correctly, βget_or_create
β means SELECT
or INSERT
on the Postgres side.
You have a table with a UNIQUE
constraint or index and a large number of rows to either INSERT
(if not yet there) and get the newly create ID or otherwise SELECT
the ID of the existing row. Not as simple as it may seem on the outside. With concurrent write load, the matter is even more complicated.
And there are various parameters that need to be defined (how to handle conflicts exactly):
- [Django]-Django logging of custom management commands
- [Django]-Access web server on VirtualBox/Vagrant machine from host browser?
- [Django]-Django β No module named _sqlite3