---
source: https://iinventedlight.com/library/notes/django-transactions.md
title: "Django database transactions"
license: CC-BY-4.0
license_url: https://creativecommons.org/licenses/by/4.0/
source_license: "BSD-3-Clause (Django docs); BSD-3-Clause (Django source docs); prose restates cited source lines in own words"
license_family: mixed-green
attribution: "Summary by iinventedlight (AI-assisted). Sources: Django docs, Database transactions; Django source docs, transactions.txt. BSD-3-Clause (https://raw.githubusercontent.com/django/django/main/LICENSE). Copyright Django Software Foundation and individual contributors."
author: "iinventedlight (synthesis of cited sources); text drafted with AI assistance"
date: 2026-11-18
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-18
as_of: 2026-11-18
confidence: medium
untested: "Not reproduced (2026-11-18). 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-web: django transactions"
tags: [django, transactions, atomic, autocommit]
client: Librarian
sources:
  - id: S1
    title: "Database transactions"
    publisher: Django docs
    url: https://docs.djangoproject.com/en/5.2/topics/db/transactions/
    accessed: 2026-11-18
    license: "BSD-3-Clause"
  - id: S2
    title: "transactions.txt"
    publisher: Django source docs
    url: https://raw.githubusercontent.com/django/django/stable/5.2.x/docs/topics/db/transactions.txt
    accessed: 2026-11-18
    license: "BSD-3-Clause"
---
# Django database transactions
**Answer:** Django's default behavior is to run in autocommit mode: each query is committed immediately unless a transaction is active. Wrap a block in `atomic()` so the work commits together, or rolls back together, at the end.

## Examples

```python
from django.db import transaction

@transaction.atomic
def transfer():
    # several writes here commit together
    pass
```

## Rules

- With `ATOMIC_REQUESTS`, Django starts a transaction before a view and commits if the response succeeds.
- Use `atomic()` as a decorator or as a context manager.

## See also

- [django-migrations](https://iinventedlight.com/library/notes/django-migrations/)
- [django-settings](https://iinventedlight.com/library/notes/django-settings/)

## Claims

- id: C1
  claim: Django's default is autocommit mode.
  source: S1
  evidence: "autocommit mode"

- id: C2
  claim: atomic() is the documented transaction helper.
  source: S1
  evidence: "atomic() context manager"

- id: C3
  claim: The source docs also describe autocommit mode.
  source: S2
  evidence: "autocommit mode"

## Sources

- [S1] Database transactions. Django docs. https://docs.djangoproject.com/en/5.2/topics/db/transactions/ . License: BSD-3-Clause. Accessed 2026-11-18.

- [S2] transactions.txt. Django source docs. https://raw.githubusercontent.com/django/django/stable/5.2.x/docs/topics/db/transactions.txt . License: BSD-3-Clause. Accessed 2026-11-18.

License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: Django docs, Database transactions; Django source docs, transactions.txt. BSD-3-Clause (https://raw.githubusercontent.com/django/django/main/LICENSE). Copyright Django Software Foundation and individual contributors. Text was condensed and changed from the originals.

---

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