如果来自bulk_create的peewee记录,我需要返回ids
我可以做这样的事
from models import Table
t = Table.create(**data)
print(i.id)我得到了一张新唱片的身份证
但如果我试着
t = Table.bulk_create(list[**data])
for i in t:
print(i.id)这里我得到一个错误:'t‘是'NoneType’
那么,我如何从peewee bulk_create中获得ids呢?
发布于 2019-09-09 11:26:40
如果使用的数据库支持RETURNING子句,则Peewee确实返回ID列表。因此,如果使用Postgresql,则peewee将返回ID列表。
使用bulk_create()的原因是它发出了一个高效的查询--一次插入多个行。Sqlite和mysql只提供“最后插入id”。
https://stackoverflow.com/questions/57851013
复制相似问题