Django unique_together with nullable ForeignKey
Django 2.2 added a new constraints API which makes addressing this case much easier within the database. You will need two constraints: The existing tuple constraint; and The remaining keys minus the nullable key, with a condition If you have multiple nullable fields, I guess you will need to handle the permutations. Here’s an example … Read more