title: How to unittest a django database migration?
body: <p>We've changed our database, using django migrations (django v1.7+).
  The data that exists in the database is no longer valid.</p>
  
  <p>Basically I want to test a migration by, inside a unittest, constructing the pre-migration database, adding some data, applying the migration, then confirming everything went smoothly.</p>
  
  <p>How does one:</p>
  
  <ol>
  <li><p><strong>hold back the new migration when loading the unittest</strong></p>
  
  <p>I found <a href="https://github.com/django/django/blob/master/tests/migrations/test_executor.py#L24" rel="noreferrer">some stuff</a> about overriding <code>settings.MIGRATION_MODULES</code> but couldn't work out how to use it.  When I inspect <code>executor.loader.applied_migrations</code> it still lists everything.  The only way I could prevent the new migration was to actually remove the file; not a solution I can use.</p></li>
  <li><p>create a record in the unittest database (using the old model)</p>
  
  <p>If we can prevent the migration then this should be pretty straightforward.  <code>myModel.object.create(...)</code></p></li>
  <li><p>apply the migration</p>
  
  <p>I think I can probably work this out now that I've found the <a href="https://github.com/django/django/blob/master/tests/migrations/test_executor.py" rel="noreferrer">test_executor</a>: set a plan pointing to the migration file and execute it? Um, right? Got any code for that :-D</p></li>
  <li><p>confirm the old data in the database now matches the new model</p>
  
  <p>Again, I expect this should be pretty easy: just fetch the instance created before the migration and confirm it has changed in all the right ways.</p></li>
  </ol>
  
  <p>So the challenge is really just working out <strong>how to prevent the unittest from applying the latest migration script</strong> and then applying it when we're ready?</p>
  
  <hr>
  
  <p>Perhaps I have the wrong approach?  Should I create fixtures, and just confirm that they're all good at the end?  Do fixtures get loaded before the migrations are applied, or after they're all done?</p>
  
  <hr>
  
  <p>By using the <code>MigrationExecutor</code> and picking out specific migrations with <code>.migrate</code> I've been able to, maybe?, roll it back to a specific state, then roll forward one-by-one.  But that is popping up doubts; currently chasing down sqlite fudging around due to the lack of an actual ALTER TABLE instruction.  Jury still out.</p>