I have a django project that needs migration squashing. All of the RunPython functions are moving data from one column to another after making some change. If it was just for moving old data and does not affect newly created records, do I need it or not while squashing migrations or creating them from scratch? Here is an example:
# Adding the new field
migrations.AddField(
model_name='approvalrequest',
name='club',
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, to='members.club'),
)
# RunPython function call
migrations.RunPython(migrate_membership_to_enrollment, reverse_code=reverse_migration)
# RunPython function
def migrate_membership_to_enrollment(apps, schema_editor):
ApprovalRequestModel = apps.get_model('approval_requests', 'approvalrequest')
db_alias = schema_editor.connection.alias
with transaction.atomic():
requests = ApprovalRequestModel.objects.using(db_alias).all()
for request in requests:
club = request.membership.club
request.club = club
request.save()
# Deleting memberhsip field
migrations.RemoveField(
model_name='approvalrequest',
name='membership',
),
You can see we are making a change and moving existing data according to it. Now that it has been done and everyone is on the latest versions of migrations, can this method be removed altogether?