I have two tables - Team and Game.

class Team(models.Model):
    team_id = models.IntegerField(primary_key=True)
    teamname = models.CharField(max_length=255)
    division_id = models.ForeignKey(Division)

class Game(models.Model):
    game_id = models.IntegerField(primary_key=True)
    gamedate = models.DateField()
    gamestart = models.TimetField(blank=True)
    duration = models.IntegerField()
    innings = models.IntegerField()
    hometeam_id = models.ForeignKey(Team)
    visitingteam_id = models.ForeignKey(Team)

The problem arises due to the two team_id foreign keys in the Game model -
hometeam _id and visitingteam_id. The error I get is:

Error: One or more models did not validate:
statistics.game: Accessor for field 'hometeam_id' clashes with related
field 'Team.game_set'. Add a related_name argument to the definition for
'hometeam_id'.
statistics.game: Accessor for field 'visitingteam_id' clashes with related
field 'Team.game_set'. Add a related_name argument to the definition for
'visitingteam_id'.

I looked up "related_name" argument, and tried related_name='team_id' for
both ForeignKeys, and got even more errors.

Error: One or more models did not validate:
statistics.game: Accessor for field 'hometeam_id' clashes with field
'Team.team_id'. Add a related_name argument to the definition for
'hometeam_id'.
statistics.game: Reverse query name for field 'hometeam_id' clashes with
field 'Team.team_id'. Add a related_name argument to the definition for
'hometeam_id'.
statistics.game: Accessor for field 'hometeam_id' clashes with related
field 'Team.team_id'. Add a related_name argument to the definition for
'hometeam_id'.
statistics.game: Reverse query name for field 'hometeam_id' clashes with
related field 'Team.team_id'. Add a related_name argument to the definition
for 'hometeam_id'.
statistics.game: Accessor for field 'visitingteam_id' clashes with field
'Team.team_id'. Add a related_name argument to the definition for
'visitingteam_id'.
statistics.game: Reverse query name for field 'visitingteam_id' clashes
with field 'Team.team_id'. Add a related_name argument to the definition
for 'visitingteam_id'.
statistics.game: Accessor for field 'visitingteam_id' clashes with related
field 'Team.team_id'. Add a related_name argument to the definition for
'visitingteam_id'.
statistics.game: Reverse query name for field 'visitingteam_id' clashes
with related field 'Team.team_id'. Add a related_name argument to the
definition for 'visitingteam_id'.

I read the related names documentation referenced in the related_name
description, and that did not help me understand what I need to do to fix
this problem. I think I understand why django is getting confused by having
two ForeignKeys referring to one primary key in another table, but I am not
sure how to fix the problem.

Thanks!

Mark

-- 
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+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to