django orm 批量存储数据
2014-06-18 11:58
881 查看
项目中 需要大量数据的保存操作,每条执行save操作效率太低,在官网上找到bull_create 的批量存储方式,效率提高很多
...is preferable to:
Note that there are a number of caveats to this method, so make sure it’s appropriate for your use case.
This also applies to ManyToManyFields, so doing:
...is preferable to:
...where Bands and Artists have a many-to-many relationship.
Insert in bulk
When creating objects, where possible, use the bulk_create() method to reduce the number of SQL queries. For example:Entry.objects.bulk_create([ Entry(headline="Python 3.0 Released"), Entry(headline="Python 3.1 Planned") ])
...is preferable to:
Entry.objects.create(headline="Python 3.0 Released") Entry.objects.create(headline="Python 3.1 Planned")
Note that there are a number of caveats to this method, so make sure it’s appropriate for your use case.
This also applies to ManyToManyFields, so doing:
my_band.members.add(me, my_friend)
...is preferable to:
my_band.members.add(me) my_band.members.add(my_friend)
...where Bands and Artists have a many-to-many relationship.
相关文章推荐
- [导入]批量插入数据的存储过程
- 批量插入数据的存储过程
- 用Saltstack的returners实现批量监控和数据存储 推荐
- 创建测试表,批量插入数据的存储过程,分页存储过程
- 关于主键列执行批量删除单表数据的存储过程,
- 利用存储过程进行批量数据添加
- django ORM数据模型的定义
- 利用存储过程批量生成数据
- 存储过程配合UpdateDaset方法批量插入Dataset数据实现代码
- mysql利用存储过程批量插入数据
- MSSQL中批量修改数据表和存储过程的所有者
- 存储过程学习-批量插入10000条数据进数据库
- Oracle利用存储过程批量insert造数据和分批提交删除的例子
- 大数据的存储和批量语句执行
- django中批量删除数据
- [导入]批量插入数据的存储过程
- sql server 批量修改数据表和存储过程的所有者(2000)或架构(2005)
- mssql 生成‘批量Insert数据的sql语句’的存储过程
- 存储过程学习-批量插入10000条数据进数据库
- 批量插入数据存储过程备忘