<s> from __future__ import unicode_literals <EOL> from django . db import models , migrations <EOL> def set_app ( apps , schema_editor ) : <EOL> Data = apps . get_model ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> for data in Data . objects . select_related ( '<STR_LIT:version>' ) . all ( ) : <EOL> data . app = data . version . app <EOL> data . save ( ) <EOL> class Migration ( migrations . Migration ) : <EOL> dependencies = [ <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ] <EOL> operations = [ <EOL> migrations . AddField ( <EOL> model_name = '<STR_LIT:data>' , <EOL> name = '<STR_LIT>' , <EOL> field = models . ForeignKey ( to = '<STR_LIT>' , null = True ) , <EOL> preserve_default = True , <EOL> ) , <EOL> migrations . RunPython ( set_app ) , <EOL> migrations . RemoveField ( '<STR_LIT:data>' , '<STR_LIT:version>' ) , <EOL> ] </s>
