← All notes

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

Sources

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

Permanent ID: iil:note:wbq37smb

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.},
}

Markdown

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.

All artifact files (JSON index)

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.