I have a CSV file with hundreds of data, I want to insert everything into my SQLite DB in my Django app. Inputting each value one by one will be a complete waste of time. What is a more efficient way to approach this?
Asked
Active
Viewed 110 times
1 Answers
1
The best approach in this case, is to use the bulk_create.
From the doc:
bulk_create(objs, batch_size=None, ignore_conflicts=False)
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), and returns created objects as a list, in the same order as provided:
Link to doc: https://docs.djangoproject.com/en/dev/ref/models/querysets/#bulk-create

Mattia
- 961
- 13
- 25
-
Thanks. Let me try that – Somto Sep 12 '21 at 21:03