Electronics & Programming


Open Source electronics development and programming

  • You are not logged in.
  • Root
  • » Django
  • » Primary key error for ManyToManyField in a legacy database [RSS Feed]

#1 June 19, 2010 10:48:54

Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

Primary key error for ManyToManyField in a legacy database

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',
class Meta:
db_table = 'grouping'
ordering =

class TeamGrouping(models.Model):
id = models.AutoField(primary_key=True,
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: 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


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
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.


  • Root
  • » Django
  • » Primary key error for ManyToManyField in a legacy database [RSS Feed]

Board footer

Moderator control

Enjoy the 13th of December

The Forums are managed by develissimo stuff members, if you find any issues or misplaced content please help us to fix it. Thank you! Tell us via Contact Options
Leave a Message
Welcome to Develissimo Live Support