Django unapply migration
<p>I have a custom made migration:</p>

<pre><code>class Migration(migrations.Migration):

    dependencies = [('blah', 'my_previous_migration'),]

    operations = [
        migrations.RunSQL(
            sql=[("SQL HERE")],
            reverse_sql=[("SQL UNDO HERE")])
    ]
</code></pre>

<p>This migration is already applied. I want to create a migration to undo that migration, basically following what the docs say: <a href="https://docs.djangoproject.com/es/1.10/ref/migration-operations/#runsql" rel="nofollow">unapply migration</a></p>

<p>But I can't find any reference on how to unapply a migration or have a migration run the <code>reverse_sql</code> portion of the migration.</p>

<p>Let's call the snippet <code>accident</code> and the additional one <code>fix</code>.</p>

<p>When writing custom SQL migrations you should usually provide the reverse part otherwise you can not roll it back to prior state without loosing the integrity of your schema and/or data.</p>

<p><code>accident</code> should provide sql to revert itself. The <code>fix</code> that rolls <code>accident</code> back should therefor consist of both operations interchanged.</p>

<p>You might want to read <a href="https://docs.djangoproject.com/es/1.10/topics/migrations/#migration-squashing" rel="nofollow">about squashing migrations</a> afterwards.</p>

<p>EDIT: the term operations might by confusing as it is part of the migration system :) - will say: interchange <code>sql</code> and <code>reverse_sql</code> in <code>fix</code> migration</p>

python django migration