Defer or load only some Django fields, and when a covering index helps
Answer: If a model has fields you may not need when you initially fetch the data, defer() tells Django not to retrieve them from the database. only() is essentially the opposite of defer(). The fields passed into this method are loaded immediately when the queryset is evaluated, unless they are already specified as deferred.
defer() and only()
A queryset that has deferred fields will still return model instances. Accessing a deferred field retrieves it from the database. You can never defer the loading of the primary key. Pass None to defer() if you want to clear the set of deferred fields. If almost all the fields need to be deferred, only() can be simpler.
Covering indexes
When the query only needs those selected columns, a covering index can make the SQL cheaper. A covering index contains all the columns of the original table that are used by the query, both the search terms and the output. With a covering index, SQLite never needs to consult the original table. A covering index contains all the columns of the original table that are used by the query.
| defer() | only() | |---|---| | defer() | Do not retrieve named fields from the database | | only() | Opposite of defer(); listed fields are loaded immediately | | primary key | You can never defer loading it | | covering index | Index that holds search terms and output columns |
See also
Claims
- id: C1 claim: defer() tells Django not to retrieve named fields from the database until they are accessed. source: S1 evidence: "you can tell Django not to retrieve them from the database"
- id: C2 claim: only() is the opposite of defer() and loads the fields passed into the method. source: S1 evidence: "The only() method is essentially the opposite of defer()"
- id: C3 claim: A SQLite covering index can satisfy a query without consulting the original table. source: S2 evidence: "SQLite never needs to consult the original table"
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] Query Planning. SQLite. https://www.sqlite.org/queryplanner.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, Query Planning. BSD-3-Clause; Public-Domain. Text was condensed and changed from the originals.
License: CC-BY-4.0 · Summary by iinventedlight (AI-assisted). Sources: Django docs, QuerySet API reference; SQLite, Query Planning. BSD-3-Clause; Public-Domain.
Cite this
iinventedlight. 2026. "Defer or load only some Django fields, and when a covering index helps." iinventedlight Library, iil:note:wbq37smb, version of 2026-11-19. https://iinventedlight.com/library/notes/django-defer-only/. License: CC-BY-4.0.
@misc{iil_note_wbq37smb,
author = {{iinventedlight}},
title = {{Defer or load only some Django fields, and when a covering index helps}},
howpublished = {iinventedlight Library},
year = {2026},
date = {2026-11-19},
url = {https://iinventedlight.com/library/notes/django-defer-only/},
note = {Permanent ID iil:note:wbq37smb. License: CC-BY-4.0.},
}
Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com. Or Report a correction (no account needed).
Extra files beside this note
These files use this note's license, shown below. Paper extras retain their reproduction status; a link is not a reproduction.
- django-defer-only.table.json (table; CC-BY-4.0)
- django-defer-only.schema.json (schema; CC-BY-4.0)
For language models and agents: start at /llms.txt | /agents.md | /.well-known/agent-library.json. This page in Markdown: /library/notes/django-defer-only.md.