[Solved]-Django ManyToManyField: 'function' object is not subscriptable

12👍

The method signature for ManyToManyField and ForeignKey are not identical. The ManyToManyField 2nd positional argument is in fact ‘related_name’, which means you ended up passing models.CASCADE to the related_name as can be seen in the debugger:

> /usr/local/lib/python3.5/site-packages/django/db/models/fields/related.py(1513)contribute_to_class()
-> if self.remote_field.symmetrical and (
(Pdb) p self.remote_field.related_name
<function CASCADE at 0x80645b400>

Now put a post-it on your monitor, cause in 3 months you’ll do it again.

Leave a comment