Search code examples
djangobulkinsertdjango-pyodbc

django-pyodbc bulk_create is broken


When calling bulk_create() using django-pyodbc backend, an insert statement is run for each object in the batch. The behavior should be to run a single insert statement per batch.

Is this a bug, or is there a way to alter this behavior?

Versions:

  • django==1.7
  • pyodbc==3.0.10
  • django-pyodbc==1.0.1
  • FreeTDS v1.00.21
  • unixODBC v2.3.4

Solution

  • I'm betting the version of django-pyodbc you're using doesn't support bulk insert. I would recommend using django-pyodbc-azure, which you can install with:

    pip install django-pyodbc-azure<1.8
    

    django-pyodbc-azure matches it's version numbers to Django's, so you'll want the latest / greatest version from the 1.7 branch (thus, <1.8).

    It should support bulk_insert():

    https://github.com/michiya/django-pyodbc-azure/blob/adc5d88a9928cecc0e9d33aacca301e0084ff824/sql_server/pyodbc/features.py#L15

    I'd also recommend upgrading to Django 1.8 (long term support) or 1.10 (current release), as security patches and bug fixes are no longer being issued for 1.7. Good luck!