#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
-------------------------------------+-------------------------------------
Changes (by Odero):
* needs_better_patch: => 0
* needs_tests: => 0
* needs_docs: => 0
Old description:
> 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.
> }}}
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):
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.
}}}
--
--
Ticket URL: <https://code.djangoproject.com/ticket/27311#comment:1>
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.06fe3e8ce2db48dfee8fc1533ef30c8a%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.