[Django]-Django ManyToMany relation add() error

6👍

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)
pl.mentionedby.add(prt)

0👍

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?

👤Mez

Leave a comment