title: Django Model with composite primary key isn't updated
body: <p>I have a model with composite primary key</p>
  <blockquote>
  <pre><code>class ChatUserModel(CModelMixin):
      user = models.ForeignKey(Users, models.DO_NOTHING, primary_key=True)
      chat = models.ForeignKey(ChatModel, models.DO_NOTHING)
      chat_permissions = models.IntegerField(blank=True, null=True)
  
      class Meta:
          managed = True
          db_table = 'tbl_chat_users'
          unique_together = (('user', 'chat'),)
  </code></pre>
  </blockquote>
  <p>And service, which use this model</p>
  <blockquote>
  <pre><code>def connect_to_chat(self, serializer: ChatInfoSerializer) -&gt; ChatUserModel:
  
      chat_id = serializer.validated_data.get('chat')
  
      if ChatUserModel.objects.filter(user_id=self.user.id, chat_id=chat_id).exists():
          raise exceptions.ValidationError('User is already member of this chat')
  
      bundle = ChatUserModel.objects.create(user=self.user, chat_id=chat_id)
  
  
      if self.user.status == enum_status_of_user.confirmed_email:
          bundle.chat_permissions = ChatPermissions.canWrite.value
          bundle.save()
  
      return bundle
  </code></pre>
  </blockquote>
  <p>when running, I get an error:</p>
  <blockquote>
  <p>Traceback (most recent call last):   File
  &quot;/Users/tatyanakorneeva/.local/share/virtualenvs/webcam-backend-GgKKOkUN/lib/python3.9/site-packages/django/db/backends/utils.py&quot;,
  line 84, in _execute
  return self.cursor.execute(sql, params) psycopg2.errors.UniqueViolation: duplicate key value violates unique
  constraint &quot;pk_tbl_chat_user_user_id&quot; DETAIL:  Key (user_id,
  chat_id)=(26b01213-b9c3-4abc-b1d2-f7213781a2c6,
  ef4f0c4f-8edf-42b5-b01f-880856d55cd4) already exists.</p>
  <p>The above exception was the direct cause of the following exception:</p>
  <p>Traceback (most recent call last):   File
  &quot;/Users/tatyanakorneeva/.local/share/virtualenvs/webcam-backend-GgKKOkUN/lib/python3.9/site-packages/django/core/handlers/exception.py&quot;,
  line 47, in inner
  response = get_response(request)   File &quot;/Users/tatyanakorneeva/.local/share/virtualenvs/webcam-backend-GgKKOkUN/lib/python3.9/site-packages/django/core/handlers/base.py&quot;,
  line 181, in _get_response
  response = wrapped_callback(request, *callback_args, **callback_kwargs)   File &quot;/Users/tatyanakorneeva/.local/share/virtualenvs/webcam-backend-GgKKOkUN/lib/python3.9/site-packages/django/views/decorators/csrf.py&quot;,
  line 54, in wrapped_view
  return view_func(*args, **kwargs)   File &quot;/Users/tatyanakorneeva/.local/share/virtualenvs/webcam-backend-GgKKOkUN/lib/python3.9/site-packages/django/views/generic/base.py&quot;,
  line 70, in view
  return self.dispatch(request, *args, **kwargs)   File &quot;/Users/tatyanakorneeva/.local/share/virtualenvs/webcam-backend-GgKKOkUN/lib/python3.9/site-packages/rest_framework/views.py&quot;,
  line 509, in dispatch
  response = self.handle_exception(exc)   File &quot;/Users/tatyanakorneeva/.local/share/virtualenvs/webcam-backend-GgKKOkUN/lib/python3.9/site-packages/rest_framework/views.py&quot;,
  line 469, in handle_exception
  self.raise_uncaught_exception(exc)   File &quot;/Users/tatyanakorneeva/.local/share/virtualenvs/webcam-backend-GgKKOkUN/lib/python3.9/site-packages/rest_framework/views.py&quot;,
  line 480, in raise_uncaught_exception
  raise exc   File &quot;/Users/tatyanakorneeva/.local/share/virtualenvs/webcam-backend-GgKKOkUN/lib/python3.9/site-packages/rest_framework/views.py&quot;,
  line 506, in dispatch
  response = handler(request, *args, **kwargs)   File &quot;/Users/tatyanakorneeva/projects/webcam_test_dev/webcam-backend/webcam69/chat/views/ConnectChatView.py&quot;,
  line 18, in post
  chat.connect_to_chat(serializer)   File &quot;/Users/tatyanakorneeva/projects/webcam_test_dev/webcam-backend/webcam69/chat/services/ChatService.py&quot;,
  line 54, in connect_to_chat
  bundle.save()   File &quot;/Users/tatyanakorneeva/.local/share/virtualenvs/webcam-backend-GgKKOkUN/lib/python3.9/site-packages/django/db/models/base.py&quot;,
  line 753, in save
  self.save_base(using=using, force_insert=force_insert,   File &quot;/Users/tatyanakorneeva/.local/share/virtualenvs/webcam-backend-GgKKOkUN/lib/python3.9/site-packages/django/db/models/base.py&quot;,
  line 790, in save_base
  updated = self._save_table(   File &quot;/Users/tatyanakorneeva/.local/share/virtualenvs/webcam-backend-GgKKOkUN/lib/python3.9/site-packages/django/db/models/base.py&quot;,
  line 872, in _save_table
  updated = self._do_update(base_qs, using, pk_val, values, update_fields,   File
  &quot;/Users/tatyanakorneeva/.local/share/virtualenvs/webcam-backend-GgKKOkUN/lib/python3.9/site-packages/django/db/models/base.py&quot;,
  line 926, in _do_update
  return filtered._update(values) &gt; 0   File &quot;/Users/tatyanakorneeva/.local/share/virtualenvs/webcam-backend-GgKKOkUN/lib/python3.9/site-packages/django/db/models/query.py&quot;,
  line 803, in _update
  return query.get_compiler(self.db).execute_sql(CURSOR)   File &quot;/Users/tatyanakorneeva/.local/share/virtualenvs/webcam-backend-GgKKOkUN/lib/python3.9/site-packages/django/db/models/sql/compiler.py&quot;,
  line 1522, in execute_sql
  cursor = super().execute_sql(result_type)   File &quot;/Users/tatyanakorneeva/.local/share/virtualenvs/webcam-backend-GgKKOkUN/lib/python3.9/site-packages/django/db/models/sql/compiler.py&quot;,
  line 1156, in execute_sql
  cursor.execute(sql, params)   File &quot;/Users/tatyanakorneeva/.local/share/virtualenvs/webcam-backend-GgKKOkUN/lib/python3.9/site-packages/django/db/backends/utils.py&quot;,
  line 98, in execute
  return super().execute(sql, params)   File &quot;/Users/tatyanakorneeva/.local/share/virtualenvs/webcam-backend-GgKKOkUN/lib/python3.9/site-packages/django/db/backends/utils.py&quot;,
  line 66, in execute
  return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)   File
  &quot;/Users/tatyanakorneeva/.local/share/virtualenvs/webcam-backend-GgKKOkUN/lib/python3.9/site-packages/django/db/backends/utils.py&quot;,
  line 75, in _execute_with_wrappers
  return executor(sql, params, many, context)   File &quot;/Users/tatyanakorneeva/.local/share/virtualenvs/webcam-backend-GgKKOkUN/lib/python3.9/site-packages/django/db/backends/utils.py&quot;,
  line 84, in _execute
  return self.cursor.execute(sql, params)   File &quot;/Users/tatyanakorneeva/.local/share/virtualenvs/webcam-backend-GgKKOkUN/lib/python3.9/site-packages/django/db/utils.py&quot;,
  line 90, in <strong>exit</strong>
  raise dj_exc_value.with_traceback(traceback) from exc_value   File &quot;/Users/tatyanakorneeva/.local/share/virtualenvs/webcam-backend-GgKKOkUN/lib/python3.9/site-packages/django/db/backends/utils.py&quot;,
  line 84, in _execute
  return self.cursor.execute(sql, params) django.db.utils.IntegrityError: duplicate key value violates unique
  constraint &quot;pk_tbl_chat_user_user_id&quot; DETAIL:  Key (user_id,
  chat_id)=(26b01213-b9c3-4abc-b1d2-f7213781a2c6,
  ef4f0c4f-8edf-42b5-b01f-880856d55cd4) already exists.</p>
  </blockquote>
  <p>Object being created, then we go into the loop with 'if' (condition is true) - the object cannot be updated.
  I think Django instead update instance try create, but i don't know why.
  Parameter force_update=True didn't help me.</p>