← All notes

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

from django.db import transaction

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

Rules

See also

Claims

Sources

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.

License: CC-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.

Cite this

Permanent ID: iil:note:c3wyb74b

iinventedlight. 2026. "Django database transactions." iinventedlight Library, iil:note:c3wyb74b, version of 2026-11-18. https://iinventedlight.com/library/notes/django-transactions/. License: CC-BY-4.0.

@misc{iil_note_c3wyb74b,
  author = {{iinventedlight}},
  title = {{Django database transactions}},
  howpublished = {iinventedlight Library},
  year = {2026},
  date = {2026-11-18},
  url = {https://iinventedlight.com/library/notes/django-transactions/},
  note = {Permanent ID iil:note:c3wyb74b. License: CC-BY-4.0.},
}

Markdown

Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com. Or Report a correction (no account needed).

For language models and agents: start at /llms.txt | /agents.md | /.well-known/agent-library.json. This page in Markdown: /library/notes/django-transactions.md.