Python 2.7.9 Django 1.7 MySQL 5.6
I would like to populate a whole bunch of instances of objects belonging to several classes, put them in a single create() request, open a database connection, execute the request, and then close. My main motivation is performance, but compact code is also a plus.
The functionality of bulk_create() seems to be exactly what I want, but I violate at least one of the warnings listed here , i.e.
He does not work with many relationships.
and
It does not work with child models in a multi-table inheritance scenario.
These restrictions are also described in the source code :
But the error was returned when I try to make it general
ValueError: unable to create an inherited model array
My models do not seem to contain many-to-many fields or foreign keys. I donβt quite understand what inheritance scenarios on several tables they mean, so I'm not sure if this is my problem. I was hoping I could slip into my structure, which looks like this, but then I got a general error, so no cubes:
child class with OneToOneField---\ \ child class with OneToOneField----->---concrete parent class / child class with OneToOneField---/
As for the workarounds suggested in the source, # 1 is not an option for me, and # 2 does not look attractive, because I assume that this will entail a donation of performance gains for which I am going.
Are there other workarounds that could mimic bulk_create() when handling inheritance, like this, and not give up performance gains? Do I need to return to raw SQL? I would not mind creating a separate collection and doing a separate INSERT / create() for each type of child objects.