title: IntegrityError: distinguish between unique constraint and not null violations
body: <p>I have this code:</p>
  
  <pre><code>try:
      principal = cls.objects.create(
          user_id=user.id,
          email=user.email,
          path='something'
      )
  except IntegrityError:
      principal = cls.objects.get(
          user_id=user.id,
          email=user.email
      )
  </code></pre>
  
  <p>It tries to create a user with the given id and email, and if there already exists one - tries to get the existing record. </p>
  
  <p>I know this is a bad construction and it will be refactored anyway. But my question is this:</p>
  
  <p>How do i determine what kind of <code>IntegrityError</code> has happened: the one related to <code>unique</code> constraint violation (there is unique key on (user_id, email)) or the one related to <code>not null</code> constraint (<code>path</code> cannot be null)?</p>