99
Use “pk: null” instead of “pk: 1” (or whatever), which will result in the PK being set to None, and when the object is saved a primary key will be assigned.
This works for YAML at least, I’m guessing you’re using that if you are creating by hand.
13
You should have a look at Natural Keys if you’re wiling to add relation without using pk’s
https://docs.djangoproject.com/en/dev/ref/django-admin/#dumpdata-app-label-app-label-app-label-model
- [Django]-Django – how to visualize signals and save overrides?
- [Django]-Create empty queryset by default in django form fields
- [Django]-How to customize activate_url on django-allauth?
- [Django]-Exclude fields in Django admin for users other than superuser
- [Django]-Inject errors into already validated form?
- [Django]-Cron and virtualenv
0
If you check out the manage.py dumpdata
command, you will see some options called --natural-foreign
, --natural-primary
, etc. If you look at the output you can see that the objects are dumped without using primary keys or foreign keys.
- [Django]-Python Asyncio in Django View
- [Django]-How to See if a String Contains Another String in Django Template
- [Django]-Pass request context to serializer from Viewset in Django Rest Framework
Source:stackexchange.com