19👍
In my case TestModel.objects.create(testkey__id=1)
didn’t work for me so I had to put one underscore instead of two, for example
TestModel.objects.create(testkey_id=1)
- [Django]-Django test runner not finding tests
- [Django]-Django Setup Default Logging
- [Django]-How to override and extend basic Django admin templates?
13👍
In get_or_create
it will fail in get. So to make get_or_create
work below is the solution:
TestModel.objects.get_or_create(testkey=TestModel2(id=1))
Reference:
https://code.djangoproject.com/ticket/13915
- [Django]-What is the purpose of apps.py in Django 1.9?
- [Django]-Check if key exists in a Python dict in Jinja2 templates
- [Django]-How to do SELECT MAX in Django?
Source:stackexchange.com