<reponame>Swiss-Polar-Institute/spi-media-gallery
# Generated by Django 2.2.4 on 2019-08-09 16:48

from django.db import migrations, models
import django.db.models.deletion

def migrate_tags_to_table(apps, schema_editor):
    TagName = apps.get_model('main', 'TagName')
    Tag = apps.get_model('main', 'Tag')

    for tag in Tag.objects.all():
        tag_name = TagName()
        tag_name.name = tag.tag
        tag_name.save()

        tag.name = tag_name
        tag.save()


class Migration(migrations.Migration):

    dependencies = [
        ('main', '0029_auto_20190809_1121'),
    ]

    operations = [
        migrations.CreateModel(
            name='TagName',
            fields=[
                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('name', models.CharField(max_length=255)),
            ],
        ),
        migrations.AddField(
            model_name='tag',
            name='name',
            field=models.ForeignKey(default=1, on_delete=django.db.models.deletion.PROTECT, to='main.TagName'),
            preserve_default=False,
        ),

        migrations.RunPython(migrate_tags_to_table),

        migrations.AlterUniqueTogether(
            name='tag',
            unique_together={('name', 'importer')},
        ),
        migrations.RemoveField(
            model_name='tag',
            name='tag',
        ),
    ]

# Generated by Django 2.2.4 on 2019-08-09 16:48

from django.db import migrations, models
import django.db.models.deletion

def migrate_tags_to_table(apps, schema_editor):
    TagName = apps.get_model('main', 'TagName')
    Tag = apps.get_model('main', 'Tag')

    for tag in Tag.objects.all():
        tag_name = TagName()
        tag_name.name = tag.tag
        tag_name.save()

        tag.name = tag_name
        tag.save()


class Migration(migrations.Migration):

    dependencies = [
        ('main', '0029_auto_20190809_1121'),
    ]

    operations = [
        migrations.CreateModel(
            name='TagName',
            fields=[
                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('name', models.CharField(max_length=255)),
            ],
        ),
        migrations.AddField(
            model_name='tag',
            name='name',
            field=models.ForeignKey(default=1, on_delete=django.db.models.deletion.PROTECT, to='main.TagName'),
            preserve_default=False,
        ),

        migrations.RunPython(migrate_tags_to_table),

        migrations.AlterUniqueTogether(
            name='tag',
            unique_together={('name', 'importer')},
        ),
        migrations.RemoveField(
            model_name='tag',
            name='tag',
        ),
    ]
# Generated by Django 2.2.4 on 2019-08-09 16:48