← Fullstack with Vue.jsQuestion 59 of 62
What does QuerySet.defer() do in Django ORM?
📘 Explanation
defer() tells Django to leave out certain fields from the initial SQL query and fetch them with an extra query only if you actually access them, which saves resources when you don't need every field upfront. The wrong options misdescribe this: defer() doesn't permanently remove fields or raise errors, doesn't still include them in the SELECT, and doesn't cache everything else in memory.
Related questions
- Given a Book model with a ForeignKey to Author, how do you query the most expensive book per author in Django ORM?
- When do you use selectrelated() vs prefetchrelated() in Django?
- What does Django's extra() method do, and when would you use it?
- What's the difference between annotate() vs values().annotate() in Django ORM?
- When you call selectrelated("author") on a Book queryset, what kind of SQL join does Django generate? Does it always…
← PreviousNo login needed