title: `No Unique Constraint` error on Django ForiegnKey w/ unique PK
body: <p>There are dozens of similar posts, but typically the OP isn't relying on the built-in, auto-incrementing, and already-unique PK value so they tend to have the same answers. None have answered my question.</p>
  <p>I keep getting this error when running <code>python manage.py migrate</code> on my (Django/Postgres) production Google Cloud server:</p>
  <blockquote>
  <p>django.db.utils.ProgrammingError: there is no unique constraint matching given keys for referenced table &quot;api_bookgroup&quot;</p>
  </blockquote>
  <p>I understand that the error is saying &quot;Hey! I don't know which record to return, because there's no unique identifier&quot; BUT two things have me scratching my head:</p>
  <ol>
  <li><a href="https://docs.djangoproject.com/en/3.1/ref/models/fields/#django.db.models.ForeignKey.to_field" rel="nofollow noreferrer">Django Docs</a> are pretty clear that &quot;By default, Django uses the primary key of the related object&quot; - so the PK should be the unique constraint that's required.</li>
  <li>This same code runs perfectly on 3 other dev machines/databases, including our Google Cloud dev instance (Although each other instance has different data in the database)</li>
  </ol>
  <p>Point #2 makes me wonder if it's possible for Django/Postgres to somehow allow two <code>bookGroup</code> records with the same PK without throwing terrible errors? if that's the case, how would I find those records, and if not, What else could be causing this error?</p>
  <p><strong>Thanks for your Help!</strong></p>
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code># api.models.py
  
  class BookGroup(models.Model):
      name = models.CharField(max_length=255, default='')
      description = models.CharField(max_length=255, blank=True)
      code = models.CharField(max_length=255, unique=True)
      ...
      
  class HistBookGroup(HistoricalRecord):
      master_id = models.ForeignKey(BookGroup, on_delete=models.CASCADE, null=True, related_name='historical_data')
      name = models.CharField(max_length=255, default='')
      ...</code></pre>
  </div>
  </div>
  </p>
  <pre><code>class HistBookGroup(HistoricalRecord):
      master_id = models.ForeignKey(BookGroup, on_delete=models.CASCADE, null=True, related_name='historical_data')
      updated_by_user_id = models.ForeignKey(UserProfile, on_delete=models.CASCADE, related_name='hist_bookgroups_updated')
      name = models.CharField(max_length=255, default='')
  </code></pre>