Wednesday, July 4, 2012

Re: specify the foreign keys in a ManyToManyField created table?

On Wed, 4 Jul 2012 06:39:40 -0700 (PDT), eiriks <eirstav@gmail.com>
declaimed the following in gmane.comp.python.django.user:

>
> Heres the model with the ManyToManyField:
>
> class Dagensrepresentanter(models.Model):
> person = models.ForeignKey(Personer,
> related_name='dagensrepresentanter_person')
> vara_for = models.ForeignKey(Personer, blank=True, null=True,
> related_name='dagensrepresentanter_vara_for')
> komiteer = models.ManyToManyField(Komiteer)
>
> it generats this intermediate table (I only included the fields
> for simplicity):
>
> `id` int(11) NOT NULL AUTO_INCREMENT,
> > *`dagensrepresentanter_id` int(11) NOT NULL,*
> > `komiteer_id` varchar(150) NOT NULL,
>
I think I'd need to see the "komiteer" model.

By definition, an intersection table uses the primary key field for
each of the two related tables (technically, as foreign keys, but it
appears the database representation isn't showing that). In this case,
those should be the primary key for "dagensrepresentanter" (the
generated auto-increment ID field), AND the primary key field for the
"komiteer" table (which seems to have been defined as a character field
rather than an auto-increment field -- hence my comment about needing to
see the model definition for that table).

>
> The line in italics is a int(11), and probably links fine with the auto

This is a text group, so formatting doesn't get through... I see a
line delimited by asterisks (which in the old rich text mime format
signified *bold*, the others were /italic/ and _underscore_).
--
Wulfraed Dennis Lee Bieber AF6VN
wlfraed@ix.netcom.com HTTP://wlfraed.home.netcom.com/

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

No comments:

Post a Comment