title: Django unique_together with nullable ForeignKey
body: <p>I'm using Django 1.8.4 in my dev machine using Sqlite and I have these models:</p>
  
  <pre><code>class ModelA(Model):
      field_a = CharField(verbose_name='a', max_length=20)
      field_b = CharField(verbose_name='b', max_length=20)
  
      class Meta:
          unique_together = ('field_a', 'field_b',)
  
  
  class ModelB(Model):
      field_c = CharField(verbose_name='c', max_length=20)
      field_d = ForeignKey(ModelA, verbose_name='d', null=True, blank=True)
  
      class Meta:
          unique_together = ('field_c', 'field_d',)
  </code></pre>
  
  <p>I've run proper migration and registered them in the Django Admin. So, using the Admin I've done this tests:</p>
  
  <ul>
  <li>I'm able to create ModelA records and Django prohibits me from creating duplicate records - as expected!</li>
  <li>I'm not able to create identical ModelB records when field_b is not empty</li>
  <li>But, I'm able to create identical ModelB records, when using field_d as empty</li>
  </ul>
  
  <p>My question is: How do I apply unique_together for nullable ForeignKey?</p>
  
  <p>The most recent answer I found for this problem has 5 year... I do think Django have evolved and the issue may not be the same.</p>