From 2b86baeda9914bf682728c83dd169099628d6c11 Mon Sep 17 00:00:00 2001 From: Paul Tagliamonte Date: Fri, 27 Feb 2015 11:39:03 -0500 Subject: [PATCH] Work around bulk_create consistency issues bulk_create ends up causing pk consistency issues when doing an update, even though we did a and the PK is clear. The .save() on each shockingly works. I'm switching this until this is entirely understood. --- opencivicdata/management/commands/loaddivisions.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/opencivicdata/management/commands/loaddivisions.py b/opencivicdata/management/commands/loaddivisions.py index 14abb78..b989dc3 100644 --- a/opencivicdata/management/commands/loaddivisions.py +++ b/opencivicdata/management/commands/loaddivisions.py @@ -37,7 +37,14 @@ def load_divisions(country): # delete old ids and add new ones all at once with transaction.atomic(): Division.objects.filter(country=country).delete() - Division.objects.bulk_create(objects, batch_size=10000) + for object_ in objects: + object_.save() + # Division.objects.bulk_create(objects, batch_size=10000) + # XXX: The above line (bulk_create) ends up causing pk consistency + # issues when doing an update, even though we did a delete + # and the PK is clear. The .save() on each shockingly + # works. I'm switching this until this is entirely + # understood. print(len(objects), 'divisions created')