title: Update database records from data fixtures
body: <p>How can I <strong>update an already populated Django database</strong> with records from a data fixture (or other serialized records)?</p>
  <p>I know I can use Django <a href="https://docs.djangoproject.com/en/stable/howto/initial-data/" rel="nofollow noreferrer">data fixtures to provide initial data</a>. Can I use the same already written features to <em>update</em> the database from data fixtures (or similar serialized data like a JSON document)?</p>
  <p>The “insert or update from serialised data” operation should be <a href="https://en.wiktionary.org/wiki/idempotent" rel="nofollow noreferrer">idempotent</a>:</p>
  <ul>
  <li>If a record doesn't exist (by its key) in the database, it should be inserted.</li>
  <li>If a record already exists (by its key) in the database, it should be updated to match the data fixture.</li>
  <li>The end state should be that all data from the data fixture should be updated in the database, no matter if the records already existed.</li>
  </ul>
  <p>Specifically, can I update existing rows by specifying <code>pk=null</code> and using natural keys?</p>
  <p>How can I use the existing Django “load data” features (whether <code>loaddata</code> or something else similar in Django), to <strong>read serialised data, insert records if they don't exist and update them if they already exist</strong>?</p>