gpt4 book ai didi

django - 如何显示由 prefetch_related 生成的查询

转载 作者:行者123 更新时间:2023-12-03 15:51:19 25 4
gpt4 key购买 nike

我有一个带有 prefetch_related() 的 QuerySet (使用 Prefetch 对象)

我想查看原始查询和 print(qs.query)它没有显示有关 prefetch_related 的任何信息东西。

我如何查看由于 prefetch_related 而将运行的查询?

最佳答案

查询集的 query object 只会向您显示 Django 为查询集本身生成的查询(在应用任何 prefetch_related 等之前)。

您可能需要查看 these guidelines用于检查实际发送到数据库的查询:

from django.db import connection
print(connection.queries)

或者你可以使用类似 django-debug-toolbar 的东西以显示查询。

关于django - 如何显示由 prefetch_related 生成的查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33196826/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com