- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
如果 peewee 中的记录来自 bulk_create,我需要返回 id
我可以做这样的事
from models import Table
t = Table.create(**data)
print(i.id)
然后我得到一条新记录的id
但如果我尝试
t = Table.bulk_create(list[**data])
for i in t:
print(i.id)
这里我得到一个错误:'t' is 'NoneType'
那么我怎样才能从 peewee bulk_create 中获取 ID?
最佳答案
Peewee 确实返回 ID 列表如果您使用的数据库支持 RETURNING
子句。所以,如果您使用的是 Postgresql,那么 peewee 将返回 ID 列表。
使用 bulk_create()
的原因是它发出了一个高效的查询——一次插入多行。 Sqlite 和 mysql 只提供“last insert id”。
关于python - Peewee bulk_create 返回 ID,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57851013/
我有一对一对一的关系,比如说: from django.db import models class Place(models.Model): name = models.CharField(
是否可以在具有外键关系的列上使用 bulk_create 方法? class Reports(models.Model): groupname=models.CharField(max_len
我搜索过这个,但似乎没有真正好的解决方案(大多数答案都是多年以前的)。对于需要唯一的 bulk_creating 对象,是否有任何新的好的解决方案? 好的,所以我有包含约 1000 个字典和字典 ['
我的目标是创建一个查询集的克隆,然后将其插入到数据库中。 遵循 this post 的建议,我有以下代码: qs_new = copy.copy(qs) MyModel.objects.bulk_cr
我正在使用 Django 1.6 和 postgres,对特定表的 bulk_create 会锁定整个表吗? (在我的例子中,我正在批量创建 10,000 行,这需要大约 10 秒)我已经测试过这个,
我有一个 Django 系统,可以定期为成千上万的客户计费。这是我的模型: class Invoice(models.Model): balance = models.DecimalField
如何覆盖 bulk_create 方法?我试试这个 class SomeModel(models.Model): field = models.CharField() def bulk
我有大约 400 000 个对象实例要插入到 postgres 中。我正在使用 bulk_create() 这样做,但遇到内存错误。 我的第一个想法是对实例列表进行分块: def chunks(l,
我正在尝试理解 Django 中的 bulk_create 这是我尝试转换的原始查询: for e in q: msg = Message.objects.create( re
我正在尝试在我的 PostgresQL 数据库的新表中批量创建大量记录。 表中的主键是一个名为 id 的 AutoField。 从 Django 1.10(我正在使用)开始,这应该可以在 Postgr
我正在使用 bulk_create 将数千或行加载到 postgresql 数据库中。不幸的是,某些行导致了 IntegrityError 并停止了 bulk_create 进程。我想知道是否有办法告
有没有办法获取您使用 django 1.4+ 中的 bulk_create 功能创建的项目的主键? 最佳答案 2016 自 Django 1.10 - 现在支持(仅在 Postgres 上)这里是 l
我正在使用 bulk_create 一次插入数千个用户: new_users_bulk_list.append(User(user_id=user_id, date_of_birth=dob))
如果 peewee 中的记录来自 bulk_create,我需要返回 id 我可以做这样的事 from models import Table t = Table.create(**data) pri
我正在阅读 Django bulk_create 及其一些“缺陷”: " This has a number of caveats though: 1. The model's save() meth
我需要在 django-mptt 上使用 bulk_create模型,但出现错误: django.db.utils.IntegrityError: null value in column "lft"
如果我使用 bulk_create 插入对象: objList = [a, b, c,] #none are saved model.objects.bulk_create(objList) 对象的
我有很多对象要存入数据库,代码如下: def addSthGroups(groups): for group in groups: # each group is an object
来自 bulk_create 的 Django 文档: If the model’s primary key is an AutoField it does not retrieve and set
我有一个列表,我想在数据库中为其批量创建条目。 如何在不循环遍历列表的情况下执行此操作,我认为这会消除 bulk_create 的意义。 例如: 而不是... for x in list: b
我是一名优秀的程序员,十分优秀!