Skip to content

Latest commit

 

History

History
25 lines (19 loc) · 766 Bytes

migrations-runsql-noop.md

File metadata and controls

25 lines (19 loc) · 766 Bytes

migrations.RunSQL.noop for reversible SQL migrations

migrations.RunSQL.noop provides an easy way to create "reversible" Django SQL migrations, where the reverse operation does nothing (but keeps it possible to reverse back to a previous migration state without being blocked by an irreversible migration).

from django.db import migrations


class Migration(migrations.Migration):

    dependencies = [
        ("app", "0114_last_migration"),
    ]

    operations = [
        migrations.RunSQL(
            sql="""
                update concordance_identifier
                set authority = replace(authority, ':', '_')
                where authority like '%:%'
            """,
            reverse_sql=migrations.RunSQL.noop,
        )
    ]