我的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