I’m just going through the same exercise at the moment. The approach I’ve taken is to create a list of new objects from the DataFrame and then bulk create them:
bulk_create(objs, batch_size=None)
This method inserts the provided list of objects into the database in an efficient manner (generally only 1 query, no matter how many objects there are)
An example might look like this:
# Not able to iterate directly over the DataFrame
df_records = df.to_dict('records')
model_instances = [MyModel(
field_1=record['field_1'],
field_2=record['field_2'],
) for record in df_records]
MyModel.objects.bulk_create(model_instances)