title: Django 1.8: Delete/rename a model field in data migration
body: <p>I need to change the relationship of a model field from ForeignKey to ManyToManyField. This comes with a data migration, to update the pre-existing data.</p>
  
  <p>The following is the original model (<strong>models.py</strong>):</p>
  
  <pre><code>class DealBase(models.Model):
  
      [...]
      categoria = models.ForeignKey('Categoria')
      [...]
  
      )
  </code></pre>
  
  <p>I need the model field 'categoria' to establish a many2many relationship with the model 'Categoria' in the app 'deal'.</p>
  
  <p>What I did:</p>
  
  <ol>
  <li><p>Create a new field 'categoria_tmp' in DealBase</p>
  
  <pre><code>class DealBase(models.Model):
       categoria = models.ForeignKey('Categoria')
       categoria_tmp = models.ManyToManyField('Categoria',related_name='categoria-temp')
  </code></pre></li>
  <li><p>make a schema migration</p>
  
  <blockquote>
    <p>python manage.py makemigrations</p>
  </blockquote></li>
  <li><p>Edit the migrationfile.py to migrate data from categoria to categoria-tmp </p>
  
  <pre><code>def copy_deal_to_dealtmp(apps, schema_editor):
      DealBase = apps.get_model('deal', 'DealBase')
  
      for deal in DealBase.objects.all():
          deal.categoria_tmp.add(deal.categoria)
          deal.save()
  
  class Migration(migrations.Migration):
  
      dependencies = [
        ('deal', '0017_dealbase_indirizzo'),
      ]
  
      operations = [
         migrations.AddField(
         model_name='dealbase',
         name='categoria_tmp',
         field=models.ManyToManyField(related_name='categoria-temp', to='deal.Categoria'),
         preserve_default=True,
        ),
  
         migrations.RunPython(
          copy_deal_to_dealtmp
         )
        ]
  </code></pre></li>
  <li><p>make data migration</p>
  
  <blockquote>
    <p>python manage.py migrate</p>
  </blockquote></li>
  <li><p>Finally I need to delete the column 'dealbase.categoria' and rename the column 'dealbase.categoria-tmp' to 'dealbase.categoria'</p></li>
  </ol>
  
  <p>I'm stuck at step 5.</p>
  
  <p>Could someone help me out? I cannot find online an answer, I'm using Django 1.8.</p>
  
  <p>Thanks!</p>