I'm scripting a migration tool to get my data from an old software to a new version with different data structures.
While looping through the csv-files I'm creating the objects. The problem is that every object gets created in postgres but django doesn't.
I'm getting errors like: duplicate key value violates unique constraint "api_order_pkey" DETAIL: Key (id)=(159865) already exists.
Order.objects.get(pk=159865) does return "Does not exist" But a SELECT * FROM api_order WHERE pk = 159865 directly in Postgres finds a row.
with open("order.csv","r") as f:
reader = csv.reader(f)
for row in reader:
Order.objects.create(pk = row[0], ordernr= row[1],....)`
thats of course a short version of it.
On the import of about 250.000 rows this problem appears with about 100 rows.
I had the same problem with deleting. I ran Order.objects.all().delete() but in Postgres there where still a few rows left while Order.objects.all() returned an empty Queryset.
Is there something I can do about this? Has anyone had a similar problem?