# -*- coding: utf-8 -*-
# Generated by Django 1.9.7 on 2017-03-03 09:01
from __future__ import unicode_literals

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


def update_problem_field_of_merge_request(apps, schema_editor):
    MergeRequest = apps.get_model("problems", "MergeRequest")
    db_alias = schema_editor.connection.alias
    for obj in MergeRequest.objects.using(db_alias).all():
        obj.problem = obj.source_branch.problem
        obj.save()


class Migration(migrations.Migration):

    dependencies = [
        ('problems', '0074_auto_20170301_2347'),
    ]

    operations = [
        migrations.AddField(
            model_name='mergerequest',
            name='problem',
            field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, related_name='merge_requests', to='problems.Problem', verbose_name='problem'),
        ),
        migrations.RunPython(update_problem_field_of_merge_request, migrations.RunPython.noop),
        migrations.AlterField(
            model_name='mergerequest',
            name='problem',
            field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='merge_requests',
                                    to='problems.Problem', verbose_name='problem'),
        ),
    ]
