Django model object with foreign key creation
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)
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
What you’re after is:
TestModel.objects.create(testkey_id=1)