Question about batch save objects in Django

前端 未结 5 968
一向
一向 2020-12-14 15:47

I haven\'t seen any thing on this topic in Django\'s online documents.

I am trying to save a list of objects to database, but what I can do is loop through the list

5条回答
  •  时光取名叫无心
    2020-12-14 15:51

    Unfortunately, batch inserts are something that Django 1.3 and prior do not directly support. If you want to use the ORM, then you do have to call save() on each individual object. If it's a large list and performance is an issue, you can use django.db.cursor to INSERT the items manually inside a transaction to dramatically speed the process up. If you have a huge dataset, you need to start looking at Database engine specific methods, like COPY FROM in Postgres.

提交回复
热议问题