当我做这样的事情时:
model_list = [Model(name = 'First'), Model(name = 'Second'), Model(name = 'Third')]
Model.objects.bulk_create(model_list)
我能相信他们会以同样的顺序创建吗?
那是:
pk1 = Model.objects.get(name = 'First').pk
pk2 = Model.objects.get(name = 'Second').pk
pk3 = Model.objects.get(name = 'Third').pk
(pk3 > pk2) and (pk2 > pk1)
答案 0 :(得分:2)
我认为你可以。
model_list = [Model(name = 'First'),
Model(name = 'Second'),
Model(name = 'Third')]
Model.objects.bulk_create(model_list)
此代码将转换为以下SQL:
INSERT INTO app_model (name) VALUES ('First'), ('Second'), ('Third')
常规SQL服务器不太可能以不同的顺序插入这些行。