I have a QuerySet with a prefetch_related()
(with Prefetch
object)
I want to see the raw query and print(qs.query)
and it doesn't show anything about the prefetch_related
stuff.
How do I see the query which will be run because of prefetch_related
?
The queryset's query
object will only show you the query that Django generates for the queryset itself (before any prefetch_related
etc. is applied).
You probably need to look at these guidelines for inspecting the query that is actually sent to your database:
from django.db import connection
print(connection.queries)
Alternatively you can use something like django-debug-toolbar to display the queries.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With