title: Is it possible to override the error message that Django shows for UniqueConstraint error? (IntegrityError)
body: <p>Using UniqueConstraint on multiple fields and it is working properly, but I want to override the error message.</p>
  
  <p>Have gone through many postings, some of them quite dated, and none seem to specify how to override this particular instance. (IntegrityError)</p>
  
  <p>Fields are User and Skill Group. I would like error message to simply say "Skill Group already in use." It currently reads "Skill group with this User and Skill group already exists." Thanks.</p>
  
  <p><strong>Updated:</strong>
  Thought I should post related code:</p>
  
  <pre><code>models.py
  class SkillGroup(models.Model):
      user = models.ForeignKey(User, on_delete=models.CASCADE)
      skill_group = models.CharField(max_length=35)
      sequence = models.IntegerField(default=999)
  
      class Meta:
          constraints = [
              models.UniqueConstraint(fields=['user', 'skill_group'], name='unique_skillgroup'),
          ]
  
      def __str__(self):
          return self.skill_group
  
      def get_absolute_url(self):
          return reverse('skillgroup-list')
  
  forms.py
  class SkillGroupForm(forms.ModelForm):
  
      class Meta:
          model = SkillGroup
          fields = ('user', 'skill_group')
          widgets = {
              'user': forms.HiddenInput,
          }
  
  views.py
  class SkillGroupCreateView(LoginRequiredMixin, CreateView):
      model = SkillGroup
      form_class = SkillGroupForm
  
      def get_initial(self):
          return {'user': self.request.user}
  
      def form_valid(self, form):
          try:
              result = super().form_valid(form)
          except IntegrityError as err:
              if str(err) == "Skill group with this User and Skill group already exists.":
                  raise IntegrityError("Skill Group already in use.")
              raise
          else:
              return result
  </code></pre>
  
  <pre><code>IntegrityError at /skillgroup/create/
  duplicate key value violates unique constraint "unique_skillgroup"
  DETAIL:  Key (user_id, skill_group)=(1, Quality Assurance) already exists.
  Request Method: POST
  Request URL:    http://localhost:8000/skillgroup/create/
  Django Version: 2.2
  Exception Type: IntegrityError
  Exception Value:    
  duplicate key value violates unique constraint "unique_skillgroup"
  DETAIL:  Key (user_id, skill_group)=(1, Quality Assurance) already exists.
  Exception Location: C:\Users\CHRIST~1\Envs\bcs\lib\site-packages\django\db\backends\utils.py in _execute, line 84
  Python Executable:  C:\Users\CHRIST~1\Envs\bcs\Scripts\python.exe
  Python Version: 3.7.2
  Python Path:    
  ['C:\\Users\\Christopher George\\bcs\\basicrecruiter',
   'C:\\Users\\CHRIST~1\\Envs\\bcs\\Scripts\\python37.zip',
   'C:\\Users\\CHRIST~1\\Envs\\bcs\\DLLs',
   'C:\\Users\\CHRIST~1\\Envs\\bcs\\lib',
   'C:\\Users\\CHRIST~1\\Envs\\bcs\\Scripts',
   'c:\\users\\christopher '
   'george\\appdata\\local\\programs\\python\\python37-32\\Lib',
   'c:\\users\\christopher '
   'george\\appdata\\local\\programs\\python\\python37-32\\DLLs',
   'C:\\Users\\CHRIST~1\\Envs\\bcs',
   'C:\\Users\\CHRIST~1\\Envs\\bcs\\lib\\site-packages']
  Server time:    Thu, 18 Apr 2019 02:53:51 +0000
  </code></pre>
  
  <pre><code>Traceback:
  Environment:
  
  
  Request Method: POST
  Request URL: http://localhost:8000/skillgroup/create/
  
  Django Version: 2.2
  Python Version: 3.7.2
  Installed Applications:
  ['recruiter.apps.RecruiterConfig',
   'crispy_forms',
   'phone_field',
   'django.contrib.admin',
   'django.contrib.auth',
   'django.contrib.contenttypes',
   'django.contrib.sessions',
   'django.contrib.messages',
   'django.contrib.staticfiles']
  Installed Middleware:
  ['django.middleware.security.SecurityMiddleware',
   'django.contrib.sessions.middleware.SessionMiddleware',
   'django.middleware.common.CommonMiddleware',
   'django.middleware.csrf.CsrfViewMiddleware',
   'django.contrib.auth.middleware.AuthenticationMiddleware',
   'django.contrib.messages.middleware.MessageMiddleware',
   'django.middleware.clickjacking.XFrameOptionsMiddleware']
  
  
  
  Traceback:
  
  File "C:\Users\CHRIST~1\Envs\bcs\lib\site-packages\django\db\backends\utils.py" in _execute
    84.                 return self.cursor.execute(sql, params)
  
  The above exception (duplicate key value violates unique constraint "unique_skillgroup"
  DETAIL:  Key (user_id, skill_group)=(1, Quality Assurance) already exists.
  ) was the direct cause of the following exception:
  
  File "C:\Users\CHRIST~1\Envs\bcs\lib\site-packages\django\core\handlers\exception.py" in inner
    34.             response = get_response(request)
  
  File "C:\Users\CHRIST~1\Envs\bcs\lib\site-packages\django\core\handlers\base.py" in _get_response
    115.                 response = self.process_exception_by_middleware(e, request)
  
  File "C:\Users\CHRIST~1\Envs\bcs\lib\site-packages\django\core\handlers\base.py" in _get_response
    113.                 response = wrapped_callback(request, *callback_args, **callback_kwargs)
  
  File "C:\Users\CHRIST~1\Envs\bcs\lib\site-packages\django\views\generic\base.py" in view
    71.             return self.dispatch(request, *args, **kwargs)
  
  File "C:\Users\CHRIST~1\Envs\bcs\lib\site-packages\django\contrib\auth\mixins.py" in dispatch
    52.         return super().dispatch(request, *args, **kwargs)
  
  File "C:\Users\CHRIST~1\Envs\bcs\lib\site-packages\django\views\generic\base.py" in dispatch
    97.         return handler(request, *args, **kwargs)
  
  File "C:\Users\CHRIST~1\Envs\bcs\lib\site-packages\django\views\generic\edit.py" in post
    172.         return super().post(request, *args, **kwargs)
  
  File "C:\Users\CHRIST~1\Envs\bcs\lib\site-packages\django\views\generic\edit.py" in post
    142.             return self.form_valid(form)
  
  File "C:\Users\Christopher George\bcs\basicrecruiter\recruiter\views.py" in form_valid
    104.         return super().form_valid(form)
  
  File "C:\Users\CHRIST~1\Envs\bcs\lib\site-packages\django\views\generic\edit.py" in form_valid
    125.         self.object = form.save()
  
  File "C:\Users\CHRIST~1\Envs\bcs\lib\site-packages\django\forms\models.py" in save
    458.             self.instance.save()
  
  File "C:\Users\CHRIST~1\Envs\bcs\lib\site-packages\django\db\models\base.py" in save
    741.                        force_update=force_update, update_fields=update_fields)
  
  File "C:\Users\CHRIST~1\Envs\bcs\lib\site-packages\django\db\models\base.py" in save_base
    779.                 force_update, using, update_fields,
  
  File "C:\Users\CHRIST~1\Envs\bcs\lib\site-packages\django\db\models\base.py" in _save_table
    870.             result = self._do_insert(cls._base_manager, using, fields, update_pk, raw)
  
  File "C:\Users\CHRIST~1\Envs\bcs\lib\site-packages\django\db\models\base.py" in _do_insert
    908.                                using=using, raw=raw)
  
  File "C:\Users\CHRIST~1\Envs\bcs\lib\site-packages\django\db\models\manager.py" in manager_method
    82.                 return getattr(self.get_queryset(), name)(*args, **kwargs)
  
  File "C:\Users\CHRIST~1\Envs\bcs\lib\site-packages\django\db\models\query.py" in _insert
    1186.         return query.get_compiler(using=using).execute_sql(return_id)
  
  File "C:\Users\CHRIST~1\Envs\bcs\lib\site-packages\django\db\models\sql\compiler.py" in execute_sql
    1332.                 cursor.execute(sql, params)
  
  File "C:\Users\CHRIST~1\Envs\bcs\lib\site-packages\django\db\backends\utils.py" in execute
    99.             return super().execute(sql, params)
  
  File "C:\Users\CHRIST~1\Envs\bcs\lib\site-packages\django\db\backends\utils.py" in execute
    67.         return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
  
  File "C:\Users\CHRIST~1\Envs\bcs\lib\site-packages\django\db\backends\utils.py" in _execute_with_wrappers
    76.         return executor(sql, params, many, context)
  
  File "C:\Users\CHRIST~1\Envs\bcs\lib\site-packages\django\db\backends\utils.py" in _execute
    84.                 return self.cursor.execute(sql, params)
  
  File "C:\Users\CHRIST~1\Envs\bcs\lib\site-packages\django\db\utils.py" in __exit__
    89.                 raise dj_exc_value.with_traceback(traceback) from exc_value
  
  File "C:\Users\CHRIST~1\Envs\bcs\lib\site-packages\django\db\backends\utils.py" in _execute
    84.                 return self.cursor.execute(sql, params)
  
  Exception Type: IntegrityError at /skillgroup/create/
  Exception Value: duplicate key value violates unique constraint "unique_skillgroup"
  DETAIL:  Key (user_id, skill_group)=(1, Quality Assurance) already exists.
  </code></pre>
  
  <p><strong>Update 2:</strong>
   Based on some reading in the Django documentation, I tried changing it to with no success:</p>
  
  <pre><code>def save(self, *args, **kwargs):
      try:
        result = super().save(*args, **kwargs)
      except IntegrityError as err:
        if str(err) == "Skill group with this User and Skill group already exists.":
          raise IntegrityError("Skill Group already in use.")
        raise
      else:
        return result
  </code></pre>