#27311: Assigning ForeignKey fields in migrations
-------------------------------------+-------------------------------------
     Reporter:  Odero                |                    Owner:  nobody
         Type:  Bug                  |                   Status:  new
    Component:  Migrations           |                  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
-------------------------------------+-------------------------------------
Changes (by Tim Graham):

 * component:  Uncategorized => Migrations


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):
>     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.
> }}}

New description:

 Trying to create the migration below which is failing. It seems like the
 same issue discussed and resolved in #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
     )
     b.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.
 }}}

--

Comment:

 I can't reproduce this. Could you provide a sample project and confirm
 your Django version?

--
Ticket URL: <https://code.djangoproject.com/ticket/27311#comment:3>
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.9a8422548d792ef2b0ddb70a080e5d18%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to