﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
27311	Assigning ForeignKey fields in migrations	Odero	nobody	"I've created the migration below which is failing. It seems like the same issue discussed and resolved here https://code.djangoproject.com/ticket/24282

{{{
def generate_invoices(apps, schema_editor):
    Payment = apps.get_model('finance', 'Payment')
    Invoice = apps.get_model('finance', 'Invoice')
    User = apps.get_model('accounts', 'User')

    payment = Payment.objects.last()

    invoice = Invoice(
        client=payment.user),
        status=5
    )
    invoice.save()

}}}

Also tried 


{{{
    invoice = Invoice(
        client=User.objects.get(pk=payment.user.pk),
        status=5
    )

}}}

In both cases I get the error:
{{{
Cannot assign ""<User: Some Client>"": ""Invoice.client"" must be a ""User"" instance.
}}}
"	Bug	new	Uncategorized	1.10	Normal		migrations, foreignkey		Unreviewed	0	0	0	0	0	0
