turn off SQL logging while keeping settings.DEBUG?

前端 未结 4 712
生来不讨喜
生来不讨喜 2020-12-14 01:31

Django logs SQL operations to an internal buffer (whether logging to file or not) when settings.DEBUG=True. Because I have long-running process that does a lot of DB operat

4条回答
  •  孤城傲影
    2020-12-14 01:47

    If still interested in tracing SQL operations for debugging purposes, you can also clean connection.queries list periodically to reclaim memory:

    from django.db import connection
    
    for i in range(start, count, size):
        objects = MyModel.objects.order_by('pk').all()[i:i + size]
        ...
        print connection.queries
        connection.queries = []
    

提交回复
热议问题