2

We can get any django query by putting .query in the end, like this:

print(MyModel.objects.all().query)

It print the resulting query, without querying the database.

Is there a way to get the query for bulk_create or bulk_update, without actually querying the database?

Additional question:

Is it possible to guess, if a bulk query may throw the below error or not (by comparing the bulk query size with max allowed query packet size)?

(1153, "Got a packet bigger than 'max_allowed_packet' bytes")
Keshav Bhatiya
  • 295
  • 3
  • 11
  • Possible dup: [How to do a batch insert in MySQL](https://stackoverflow.com/questions/5526917/how-to-do-a-batch-insert-in-mysql) – JPG Aug 20 '20 at 05:30
  • Not related...I need something in Django ORM, to pre caluculate the query length, without performing any query – Keshav Bhatiya Aug 20 '20 at 05:38
  • Probably you can't because more than just a query, and it bypasses ORM when making that query. And object size you are seeking may not be the same with packet size. ORM uses a mysqlclient, a lot could depend on that. I think simplicity is better than complex solution. If increasing packet size solves your issue, then you should use that. Here is how to do it:: https://stackoverflow.com/questions/8062496/how-to-change-max-allowed-packet-size – ruddra Aug 20 '20 at 09:32

0 Answers0