I have a legacy database setup like this: class Team(models.Model): id = models.AutoField(primary_key=True, db_column='TeamID') name = models.CharField(max_length=100, db_column='TeamName') groupings = models.ManyToManyField(Grouping, related_name='groupings', db_table='teamgrouping')
class Grouping(models.Model): id = models.AutoField(primary_key=True, db_column='GroupingID') name = models.CharField(max_length=250, db_column='GroupingName', unique=True) class Meta: db_table = 'grouping' ordering = ['name'] class TeamGrouping(models.Model): id = models.AutoField(primary_key=True, db_column='teamgroupingID') grouping = models.ForeignKey(Grouping, db_column='grouping_id') team = models.ForeignKey(Team, db_column='team_id') class Meta: db_table = 'teamgrouping' unique_together = (('grouping', 'team'), ) When I display the Team model for editing in the Admin interface, it shows up OK. All the TeamGrouping's also show up, in a neat many-to- many widget, via the "groupings" field. However, when I try and save the entry, I get this error: OperationalError at /admin/edit/team/42402/ (1054, "Unknown column 'teamgrouping.id' in 'field list'") Request Method: POST Request URL: http://127.0.0.1:8000/admin/edit/team/42402/ Django Version: 1.2.1 Exception Type: OperationalError Exception Value: (1054, "Unknown column 'teamgrouping.id' in 'field list'") Exception Location: /usr/lib/pymodules/python2.6/MySQLdb/ connections.py in defaulterrorhandler, line 35 I am not sure (a) why Django is expecting to find a "'teamgrouping.id'" (I assume because "id" is the default name of a table's primary key field?) and (b) how to tell it to use 'teamgrouping.teamgroupingID' as the primary key (as specified in the TeamGrouping class)? Note: I am not using the "through" keyword because this is only needed when there are additional fields that are required on the intermediate table. Thanks Derek -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@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.