---
source: https://iinventedlight.com/library/notes/django-on-conflict.md
title: "Handle a uniqueness conflict in Django bulk_create or SQLite UPSERT"
license: CC-BY-4.0
license_url: https://creativecommons.org/licenses/by/4.0/
source_license: "BSD-3-Clause (Django docs); Public-Domain (SQLite); prose restates cited source lines in own words"
license_family: mixed-green
attribution: "Summary by iinventedlight (AI-assisted). Sources: Django docs, QuerySet API reference; SQLite, UPSERT. BSD-3-Clause; Public-Domain."
author: "iinventedlight (synthesis of cited sources); text drafted with AI assistance"
date: 2026-11-19
status: published
approved_by: "Cole Withington, 2026-11-20 13:14 PT: \"Publish the full batch and rewrite the 6 live notes\""
checked_on: 2026-11-19
as_of: 2026-11-19
confidence: medium
untested: "Not reproduced (2026-11-19). Official docs and source files were read; no test suite, server, or API call was run for this note."
category: coding-references
topic_area: "code-python: Django update_conflicts and SQLite UPSERT"
tags: [django, bulk-create, upsert, sqlite, orm]
client: Librarian
sources:
  - id: S1
    title: "QuerySet API reference"
    publisher: Django docs
    url: https://docs.djangoproject.com/en/5.2/ref/models/querysets/
    accessed: 2026-11-19
    license: "BSD-3-Clause"
  - id: S2
    title: "UPSERT"
    publisher: SQLite
    url: https://www.sqlite.org/lang_upsert.html
    accessed: 2026-11-19
    license: "Public-Domain"
---
# Handle a uniqueness conflict in Django bulk_create or SQLite UPSERT
**Answer:** `bulk_create()` accepts `ignore_conflicts` and `update_conflicts`. `ignore_conflicts=True` tells the database to ignore failed inserts, including duplicate unique values. `update_conflicts=True` tells the database to update `update_fields` when a row insertion fails on conflicts.

## Django parameters

On PostgreSQL and SQLite, `unique_fields` that may be in conflict must be provided, in addition to `update_fields`. Enabling `ignore_conflicts` disables setting the primary key on each model instance (if the database normally supports it). These options are supported on all but Oracle for `ignore_conflicts`, and all except Oracle for `update_conflicts`.

## SQLite UPSERT

UPSERT is not standard SQL. SQLite follows the syntax established by PostgreSQL, with generalizations. The syntax in between the `ON CONFLICT` and `DO` keywords is called the "conflict target". That target names the uniqueness constraint that will trigger the upsert. Clauses are checked in the order specified. The UPSERT processing happens only for uniqueness constraints. Examples use `DO UPDATE SET` or `DO NOTHING`.

| Django | SQLite |
|---|---|
| ignore_conflicts | Ignore rows that fail constraints |
| update_conflicts | Update update_fields when insertion fails on conflicts |
| unique_fields | List of unique_fields that may be in conflict |
| ON CONFLICT | Conflict target for DO UPDATE or DO NOTHING |

## See also

- [django-querysets](https://iinventedlight.com/library/notes/django-querysets/)
- [django-models](https://iinventedlight.com/library/notes/django-models/)
- [sqlite-upsert](https://iinventedlight.com/library/notes/sqlite-upsert/)

## Claims

- id: C1
  claim: bulk_create can ignore constraint failures or update fields when an insert conflicts.
  source: S1
  evidence: "tells the database to update update_fields when a row insertion fails on conflicts"

- id: C2
  claim: On PostgreSQL and SQLite, unique_fields must be provided with update_conflicts.
  source: S1
  evidence: "a list of unique_fields that may be in conflict must be provided"

- id: C3
  claim: SQLite UPSERT uses a conflict target between ON CONFLICT and DO.
  source: S2
  evidence: "The conflict target specifies a uniqueness constraint that will trigger the upsert"

## Sources

- [S1] QuerySet API reference. Django docs. https://docs.djangoproject.com/en/5.2/ref/models/querysets/ . License: BSD-3-Clause. Accessed 2026-11-19.

- [S2] UPSERT. SQLite. https://www.sqlite.org/lang_upsert.html . License: Public-Domain. Accessed 2026-11-19.

License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: Django docs, QuerySet API reference; SQLite, UPSERT. BSD-3-Clause; Public-Domain. Text was condensed and changed from the originals.

---

Agents: [/agents.md](/agents.md) | [/.well-known/agent-library.json](/.well-known/agent-library.json).
