You are correct. Django creates a primary key of 'id' for each table as an integer by default. So foreignkey will reference that primary key which by default is an integer. If the primary key is changed to some other type, Django can still handle it. Apparently using integers is the more efficient method.
On Mon, May 6, 2019 at 12:54 PM Matthew Pava <matthew.p...@iss.com> wrote: > Well, I had always assumed that they do need to be integers, but it looks > like this has been discussed at length. > > https://groups.google.com/forum/#!topic/django-users/0utRzn98Wxo > > > > It does seem clear, though, that the superior database design uses > integers for ForeignKeys. > > And I didn’t find a way to make it clear to Django not to use an Integer > ForeignKey. Maybe something to do with the primary_key attribute on a > CharField? > > > > *From:* django-users@googlegroups.com [mailto: > django-users@googlegroups.com] *On Behalf Of *b...@tanners.org > *Sent:* Monday, May 6, 2019 12:44 PM > *To:* Django users > *Subject:* Re: ORM help with INNER JOIN and GROUP BY > > > > Just want to make sure I understand. ForeighKeys need to be integers? > > > > Only integers? > > > > > > You need a ForeignKey relationship between the two models, which is an > integer value, not a char. You’d have to do migrations to get this adjusted > properly. > > -- > 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/9697de34-3d20-4023-81a7-8ea9f257f7f1%40googlegroups.com > <https://groups.google.com/d/msgid/django-users/9697de34-3d20-4023-81a7-8ea9f257f7f1%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/27eee43ff8024c98bcf9a5e9cd4bfd89%40iss2.ISS.LOCAL > <https://groups.google.com/d/msgid/django-users/27eee43ff8024c98bcf9a5e9cd4bfd89%40iss2.ISS.LOCAL?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/CAEtabwdPi16kCzZAx6btpyRFGVn0JyaXGjL%2Bw8JTj2u6pHZxBg%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.