# coding=utf-8
from django.core.management import BaseCommand

from django.db import connection


class Command(BaseCommand):
    def handle(self, *args, **kwargs):
        cursor = connection.cursor()

        cursor.execute('update api_topicvote'
                       ' set topic_author_id=(select user_id '
                       'from api_problem where id=topic_id)')

        cursor.execute('select topic_author_id from api_topicvote ORDER by id DESC limit 1')
        row = cursor.fetchall()
        print row
