<filename>bot/plugins/stats/migrations/0008_set_game_fk.py
# -*- coding: utf-8 -*-
# Generated by Django 1.10.2 on 2016-10-05 22:33
from __future__ import unicode_literals

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


def set_game_fk(apps, _):
    Game = apps.get_model('games', 'Game')
    GameSession = apps.get_model('stats', 'GameSession')

    games = {game.name: game for game in Game.objects.all()}
    for game_session in GameSession.objects.all():
        game_session.game = games[game_session._game]
        game_session.save()


def unset_game_fk(apps, _):
    GameSession = apps.get_model('stats', 'GameSession')
    GameSession.objects.update(_game=F('game__name'))


class Migration(migrations.Migration):

    dependencies = [
        ('stats', '0007_gamesession_game'),
    ]

    operations = [
        migrations.RunPython(set_game_fk, unset_game_fk)
    ]

<filename>bot/plugins/stats/migrations/0008_set_game_fk.py
# -*- coding: utf-8 -*-
# Generated by Django 1.10.2 on 2016-10-05 22:33
from __future__ import unicode_literals

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


def set_game_fk(apps, _):
    Game = apps.get_model('games', 'Game')
    GameSession = apps.get_model('stats', 'GameSession')

    games = {game.name: game for game in Game.objects.all()}
    for game_session in GameSession.objects.all():
        game_session.game = games[game_session._game]
        game_session.save()


def unset_game_fk(apps, _):
    GameSession = apps.get_model('stats', 'GameSession')
    GameSession.objects.update(_game=F('game__name'))


class Migration(migrations.Migration):

    dependencies = [
        ('stats', '0007_gamesession_game'),
    ]

    operations = [
        migrations.RunPython(set_game_fk, unset_game_fk)
    ]

# -*- coding: utf-8 -*- # Generated by Django 1.10.2 on 2016-10-05 22:33