从Django QuerySet获取SQL [英] Getting the SQL from a Django QuerySet

查看:149
本文介绍了从Django QuerySet获取SQL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何获取Django将在QuerySet对象的数据库上使用的SQL?我试图调试一些奇怪的行为,但我不知道什么查询到数据库。感谢您的帮助。

How do I get the SQL that Django will use on the database from a QuerySet object? I'm trying to debug some strange behavior, but I'm not sure what queries are going to the database. Thanks for your help.

推荐答案

您打印查询器的查询属性。

You print the queryset's query attribute.

>>> queryset = MyModel.objects.all()
>>> print queryset.query
SELECT "myapp_mymodel"."id", ... FROM "myapp_mymodel"

这篇关于从Django QuerySet获取SQL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆