我的Django的bulk_create读了和几个“瑕疵”的:在外键中使用Django的bulk_create对象?
"
This has a number of caveats though:
1. The model's save() method will not be called, and the pre_save and post_save signals will not be sent.
2. It does not work with child models in a multi-table inheritance scenario.
3. If the model's primary key is an AutoField it does not retrieve and set the primary key attribute, as save() does.
"
我没有完全理解它。所以,如果我有对象的列表,将其传递给bulk_create:
objList = [a, b, c,] #none are saved
model.objects.bulk_create(objList)
难道我还使用外键精细这些对象呢?
for obj in objList:
o = otherModel(something='asdfasdf', fkey=obj)
o.save() # will this be fine given the caveats stated above?
那么外键关系会好吗?当它说2.它不适用于多表继承场景中的子模型,这意味着任何从另一个模型继承的模型(抽象与否)都不能使用bulk_create?
那么我将如何处理外键关系?我是否必须查询数据库以选择我刚刚插入的对象? – Derek
你应该完全避免'bulk_create'在你的情况下。只需单独创建对象。 –
那么你如何建议处理性能问题与个人保存? – Derek