title: Updating models with unique fields in Django Rest Framework
body: <p>I get a &quot;value already exists&quot; error when I try to update the existing record.</p>
  <p>example: I have 10 Companies in a database. Now I want to edit the 4th record. Am looking to update the company &quot;short_name&quot; and leaving the &quot;full_name&quot; unchanged. When I hit submit, an error message is displayed in postman for full_name field &quot;Already Exist&quot; How can I avoid this?</p>
  <p><em>Model.py</em></p>
  <pre class="lang-py prettyprint-override"><code>class CompanyProfile(models.Model):
      id                  = models.UUIDField(default=uuid.uuid4, 
                                              editable=False, 
                                              primary_key=True,
                                              verbose_name='ID',)
  
      short_name           = models.CharField(max_length=30,
                                              null=True, 
                                              blank=True,)
  
      full_name            = models.CharField(max_length=255, 
                                              unique = True,)
      def __str__(self):
          return str(self.full_name)
  </code></pre>
  <p><em>Serializers.py</em></p>
  <pre class="lang-py prettyprint-override"><code>class RegisterationCompanySerializer(serializers.ModelSerializer):
      short_name = serializers.CharField(
          max_length=30,
          validators=[UniqueValidator(queryset=CompanyProfile.objects.all(),
                                      message=&quot;Short Name already exists or already in use&quot;)],
      )
  
      full_name = serializers.CharField(
          max_length=255,
          validators=[UniqueValidator(queryset=CompanyProfile.objects.all(),
                                      message=&quot;Full Name already exists or already in use&quot;)],
      )
      class Meta:
          model = CompanyProfile
          fields = '__all__'
          extra_kwargs = {
              'short_name': {'required': True},
              'full_name': {'required': True},
          }
  </code></pre>
  <p><em>views.py</em></p>
  <pre class="lang-py prettyprint-override"><code>class MainCompanyProfileView(viewsets.ModelViewSet):
      queryset            = CompanyProfile.objects.all()
      serializer_class    = RegisterationCompanySerializer
      permission_classes  = (permissions.AllowAny,)
  
      def update(self, request, pk=id ,*args, **kwargs):
          partial = kwargs.pop('partial', False)
          instance = get_object_or_404(CompanyProfile, id = pk)
          serializer = self.get_serializer(instance, data=request.data, partial=partial)
          serializer.is_valid(raise_exception=True)
          self.perform_update(serializer)
          return super().update(request, *args, **kwargs)
  </code></pre>
  <p><em>urls.py</em></p>
  <pre class="lang-py prettyprint-override"><code>router = DefaultRouter()
  
  router.register('', MainCompanyProfileView)
  
  urlpatterns = [
      path('v1/', include(router.urls)),
  ]
  </code></pre>
  <p><em>Stacktrace</em>
  <strong>Note</strong>: There are a lot of fields in each company have made an example to sort this out
  <em>Now when I update the short_name leaving full_name unchanged</em></p>
  <pre class="lang-py prettyprint-override"><code>&gt; company/views.py(56)update()
  -&gt; partial = kwargs.pop('partial', False)
  (Pdb) n
  &gt; company/views.py(57)update()
  -&gt; instance = get_object_or_404(CompanyProfile, id = pk)
  (Pdb) n
  &gt; /views.py(58)update()
  -&gt; serializer = self.get_serializer(instance, data=request.data, partial=partial)
  (Pdb) instance
  &lt;CompanyProfile: Test Company&gt;
  (Pdb) n
  &gt; company/views.py(59)update()
  -&gt; serializer.is_valid(raise_exception=True)
  (Pdb) n
  rest_framework.exceptions.ValidationError: { 'full_name': [ErrorDetail(string='Full Name already exists or already in use', code='unique')]}
  &gt; company/views.py(59)update()
  -&gt; serializer.is_valid(raise_exception=True)
  </code></pre>
  <p><em>Validation error</em></p>
  <pre class="lang-py prettyprint-override"><code>'full_name': [ErrorDetail(string='Full Name already exists or already in use', code='unique')]}
  </code></pre>