Django migrations operations inside RunPython code

  Kiến thức lập trình

I’m working with data migrations in django, and at some point, I’ll have to run migrations.RunPython. The point is that I wish I could execute migrations operations(AddField, AlterField) under certain conditions.

For example:

def forward_migration(apps, schema_editor):
    if some_condition:
       migrations.AddField(...)

class Migration(migrations.Migration):

    dependencies = [
        ('some_app', '0002_auto_...'),
    ]

    operations = [
        migrations.RunPython(forward_migration)

Thanks in advance.

2

Theme wordpress giá rẻ Theme wordpress giá rẻ Thiết kế website Kho Theme wordpress Kho Theme WP Theme WP

LEAVE A COMMENT