0

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
  • I see no reason why you would want to do this, and I also see no question being asked here. Please clarify. Commented Sep 4, 2024 at 17:35
  • I want to add a ForeingKey to a django class with null=True if that class has records in the database, and with null=False otherwise Commented Sep 4, 2024 at 17:52

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.