Are you specifying the to_field argument, or are you letting it default?

And is the pk of the other model made by Django by default, or are you
explicitly specifying a foreign key constraint on some field of your own.

Things might be better in 2.0, but I've had my troubles with pk that isn't
an AutoField (such as made by default).

If you're only doing the standard (defaulted) stuff, it's a mystery.
Either way folks probably need to see some of your code to help out.

On Mon, Mar 5, 2018 at 5:06 PM, Malik Rumi <malik.a.r...@gmail.com> wrote:

> Hello all,
>
> Up to now, (admittedly not long - I'm not a total newbie but I still have
> a LOT to learn) when making a foreign key I would just put the pk of that
> instance in the fk field, as the docs suggest:
>
> By default ForeignKey will target the pk of the remote model but this behavior
> can be changed by using the ``to_field`` argument.
>
> *https://docs.djangoproject.com/en/2.0/_modules/django/db/models/fields/related/#ForeignKey
> <https://docs.djangoproject.com/en/2.0/_modules/django/db/models/fields/related/#ForeignKey>
> *
>
> However, recently while working with a scrapy pipeline, these fields
> started catching errors, which told me
>
> "...must be an instance of ...(foreign object)"
>
> And sure enough, if I did a get queryset for the one specific instance in
> question, that worked. My question is why, or maybe it should be, what's
> the difference, or maybe even, what's going on here, or wtf?
>
> Any light you can shed on this for me would, as always, be greatly
> appreciated.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit https://groups.google.com/d/
> msgid/django-users/5f9399d4-6a48-450a-b2bd-2e33a296b1b5%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/5f9399d4-6a48-450a-b2bd-2e33a296b1b5%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAB%2BAj0vGREMexQPAg8tpAaMP_3iL8QNPCk9WbQFZSZ9hrsksHw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to