Insert statment created by django ORM at bulk_create
<p>I am kind of new to python and django.</p>

<p>I am using <code>bulk_create</code> to insert a lot of rows and as a former DBA I would very much like to see what insert statments are being executed. I know that for querys you can use <code>.query</code> but for insert statments I can't find a command.</p>

<p>Is there something I'm missing or is there no easy way to see it? (A regular print is fine by me.)</p>

<p>The easiest way is to set <code>DEBUG = True</code> and check <code>connection.queries</code> after executing the query. This stores the raw queries and the time each query takes. </p>

<pre><code>from django.db import connection


MyModel.objects.bulk_create(...)
print(connection.queries[-1]['sql'])
</code></pre>

<p>There's more information <a href="https://docs.djangoproject.com/en/1.10/faq/models/#how-can-i-see-the-raw-sql-queries-django-is-running" rel="nofollow">in the docs</a>. </p>

<p>A great tool to make this information easily accessible is the <a href="https://github.com/jazzband/django-debug-toolbar" rel="nofollow">django-debug-toolbar</a>. </p>

python django orm