Django: loading data to update data

I have a seed_data.json device on which I have my source data.

Sometimes I add new data to this equipment and reload it, which correctly updates my data.

However, now I want to delete some data from it. So I changed my seed_data.json , for example, I had something like this:

 {"fields": {"name": "Field 0"},"model": "catalog.product","pk": 1}, {"fields": {"name": "Field 1"},"model": "catalog.product","pk": 2}, {"fields": {"name": "Field 2"},"model": "catalog.product","pk": 3}, # ... 

It has become:

 {"fields": {"name": "Field 1"},"model": "catalog.product","pk": 1}, {"fields": {"name": "Field 2"},"model": "catalog.product","pk": 2}, # ... 

But I get:

django.db.utils.IntegrityError: Problem installing fixture .....\seed_data.json

Could not load catalog.Product(pk=2): column name is not unique

Thus, there is no problem adding some data, but when you try to delete some of them, there are conflicts with the primary keys.

How can I achieve what I am trying to do?

+5
source share
1 answer

The luminaires are intended only for initial data for completely new database instances, for example, when starting tests. To modify existing data usage migrations.

+3
source

Source: https://habr.com/ru/post/1241838/


All Articles