I am trying to update a record in my database using info provided by my website's front-end using Model.objects.update(**kwargs) however on running the code I get the following error:
"'Record' with this Id already exists."
I would have expected that using the "update" method instead of the "create" method would mean that it shouldn't matter / should be expected that there is already a record with the same ID.
def find_patient(request): my_form = ExampleForm() if request.method == "POST": my_form = ExampleForm(request.POST) if my_form.is_valid(): UserInfo.objects.update(**my_form.cleaned_data) else: print(my_form.errors) context = { 'form': my_form, 'data_input': DataInput.objects, 'sections': SECTION_CHOICES } return render(request, 'example.html', context) The resulting error looks tike this:
Am I misunderstanding the use case for "update" and if so, how would I go about using kwargs to update all fields for a given record in my db?
updateaims to update all records, not just a single one. Since it includes the primary key, you thus aim to set all theids to a specific value, which of course raises an error.