import logging

from django.db import migrations, models


logger = logging.getLogger()


def update_value(apps, schema_editor):
    BearingISO = apps.get_model('bearing', 'BearingISO')
    for item in BearingISO.objects.all():
        try:
            item.value = item.name
            item.save()
        except Exception as e:
            logger.error(e)


class Migration(migrations.Migration):

    dependencies = [
        ('bearing', '0024_auto_20170726_1028'),
    ]

    operations = [
        migrations.AddField(
            model_name='bearingiso',
            name='value',
            field=models.CharField(blank=True, max_length=255, null=True, verbose_name='Value'),
        ),
        migrations.RunPython(update_value)
    ]
