def add_task_name(apps, schema_editor):
    """
    This function loops through all ScheduledTask objects and sets the task_name to a unique value, based on the
    existing task attribute, e.g.
    myapp.mytasks.hello-world
    myapp.mytasks.hello-world-1
    myapp.mytasks.hello-world-2
    """
    ScheduledTask = apps.get_model('carrot', 'ScheduledTask')
    db_alias = schema_editor.connection.alias
    index = 0
    for t in ScheduledTask.objects.using(db_alias).filter(task_name=''):
        index += 1
        task_name = '%s-%i' % (t.task, index)
        t.task_name = task_name
        t.save()
