Cerin
Cerin

Reputation: 64739

How to prevent Django fixtures from conflicting with existing data

I'm trying to do manage.py loaddata myfixture.json to purposely bulk overwrite several records in my database. However, it gives me the error:

IntegrityError: Problem installing fixture 'myfixture.json': Could not load myapp.Person(pk=1): (1062, "Duplicate entry 'Bob' for key 'name'")

I thought the behavior of loaddata was to overwrite the records if primary key matches an existing record? Am I wrong, or was this changed in Django 1.5? How do I get it to overwrite?

Upvotes: 8

Views: 4891

Answers (1)

Cerin
Cerin

Reputation: 64739

I found a way to modify Django's loaddata command to properly parse natural keys while loading, and avoid re-loading duplicates. The modified command is published here. The only differences between the official loaddata are lines 189-201.

Upvotes: 5

Related Questions