Take the 2-minute tour ×

I've got a model that looks like this,

class PL(models.Model):
    locid = models.AutoField(primary_key=True)
    mentionedby = models.ManyToManyField(PRT)

class PRT(models.Model):
    tid = ..

The resulting many to many table in mysql is formed as,

| PL_id            | int(11)    | NO   | MUL | NULL    |                | 
| PRT_id           | bigint(64) | NO   | MUL | NULL    |                | 

Now, if pl is an object of PL and prt that of PRT, then doing


gives me an error

Incorrect integer value: 'PRT object' for column 'prt_id' at row 1"



works fine - with one caveat.

I can see all the elements in pl.mentionedby.all(), but I can't go to a mentioned PRT object and see its prt.mentionedby_set.all().

Does anyone know why this happens? Whats the best way to fix it?


share|improve this question
add comment

2 Answers

Adding prt directly should work on first try. How are you retrieving pl and prt? Assuming you have some data in your database, try those commands from the Django shell and see if it works. There seems to be some missing information from the question. After running python manage.py shell:

from yourapp.models import PL
pl = PL.objects.get(id=1)
prt = PRT.objects.get(id=1)
share|improve this answer
add comment

Are these the complete models? I can only assume that something's been overriden somewhere, that probably shouldn't have been.

Can you post the full code?

share|improve this answer
Hey Mez - these are almost the complete models. The other fields are just a name, and category (both of type text/varchar), so I'm not sure what you mean by overriding something. –  viksit Aug 4 '09 at 21:09
add comment

Your Answer


