#27311: Assigning ForeignKey fields in migrations
-------------------------------------+-------------------------------------
     Reporter:  Odero                |                    Owner:  nobody
         Type:  Bug                  |                   Status:  new
    Component:  Uncategorized        |                  Version:  1.10
     Severity:  Normal               |               Resolution:
     Keywords:  migrations,          |             Triage Stage:
  foreignkey                         |  Unreviewed
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------
Description changed by Odero:

Old description:

> Trying to create 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.
> }}}

New description:

 Trying to create 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):
     A = apps.get_model('app1', 'A')
     B = apps.get_model('app1', 'B')
     User = apps.get_model('accounts', 'User')

     a = A.objects.last()

     b = B(
         client=a.user),
         status=5
     )
     invoice.save()

 }}}

 Also tried


 {{{
     b = B(
         client=User.objects.get(pk=a.user.pk),
         status=5
     )

 }}}

 In both cases I get the error:
 {{{
 Cannot assign "<User: Some User>": "B.client" must be a "User" instance.
 }}}

--

--
Ticket URL: <https://code.djangoproject.com/ticket/27311#comment:2>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/063.dc461daea86a880fa6bebfc1b383bc37%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to