# -*- coding: utf-8 -*-
# Generated by Django 1.9.3 on 2016-04-20 12:24
from __future__ import unicode_literals

from django.db import migrations


def migrate_foreign_key(apps, schema_editor):
    """
        Data migration to populate the GenericForeignKey fields.
    """
    Comment = apps.get_model('ahjo', 'Comment')
    ContentType = apps.get_model('contenttypes', 'ContentType')

    agendaitem_content_type = ContentType.objects.get(app_label='ahjo', model='agendaitem')

    for comment in Comment.objects.all():
        comment.content_type = agendaitem_content_type
        comment.object_id = comment.agendaitem.pk
        comment.save()

class Migration(migrations.Migration):

    dependencies = [
        ('ahjo', '0007_auto_20160420_1523'),
    ]

    operations = [
        migrations.RunPython(migrate_foreign_key)
    ]

# -*- coding: utf-8 -*-
# Generated by Django 1.9.3 on 2016-04-20 12:24
from __future__ import unicode_literals

from django.db import migrations


def migrate_foreign_key(apps, schema_editor):
    """
        Data migration to populate the GenericForeignKey fields.
    """
    Comment = apps.get_model('ahjo', 'Comment')
    ContentType = apps.get_model('contenttypes', 'ContentType')
    AgendaItem = apps.get_model('ahjo', 'AgendaItem')

    agendaitem_content_type = ContentType.objects.get_for_model(AgendaItem)

    for comment in Comment.objects.all():
        comment.content_type = agendaitem_content_type
        comment.object_id = comment.agendaitem.pk
        comment.save()

class Migration(migrations.Migration):

    dependencies = [
        ('contenttypes', '0001_initial'),
        ('ahjo', '0007_auto_20160420_1523'),
    ]

    operations = [
        migrations.RunPython(migrate_foreign_key)
    ]

make the migrations run on a fresh database