title: How to ensure uniqueness in create_or_update without db level unique constraint in Django
body: <p>I am using django 1.10 with MySQL 5.7.</p>
  
  <p>I have a table that has a unique_together constraint on multiple columns. But few of these columns are nullable. So the DB level uniqueness is not ensured for null entries in any of these fields.</p>
  
  <p>I am using create_or_update method to ensure the uniqueness of rows at the application level. But in race conditions, even this does not ensure uniqueness as the system is horizontally scaled and multiple processes are concurrently trying to call the create_or_update function.</p>
  
  <p>I think that this should be very a normal use-case for most of the high-scale services. How do we take care of this problem?</p>
  
  <p>From what I think, My options can be:</p>
  
  <ol>
  <li>save a string instead of keeping the entries nullable. (but it is a foreign-key field).</li>
  <li>save a formatted string based on fields of unique together column and check uniqueness on that.</li>
  </ol>
  
  <p>I feel that both these options would be unintuitive. What's be the commonly followed best practice here?</p>