I want to be able to retrieve the SQL statement being executed when calling
MyModel(**kawrgs).save()
or
MyModel.objects.create(**kwargs)
But without actually creating the object in the database. I already know I can access queries via django.db.connection.queries
and querysetobject.sql
, and I guess using transactions in some way may be useful, but seems this is a bit over my head.
Any suggestions?
Thanks!
A.
您可以找出在save()
或create()
的内部工作方式中调用了哪种方法,以对数据库运行最终的sql语句(可能是在数据库后端中的某些内容,例如cursor.execute()
),并使用模拟库来防止从执行开始并捕获其参数。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.