#21763: Misleading Error: 'ManyRelatedManager' object has no attribute 'add'
-------------------------------------+-------------------------------------
     Reporter:  anonymous            |                    Owner:  nobody
         Type:                       |                   Status:  new
  Cleanup/optimization               |                  Version:  master
    Component:  Database layer       |               Resolution:
  (models, ORM)                      |             Triage Stage:  Accepted
     Severity:  Normal               |      Needs documentation:  0
     Keywords:                       |  Patch needs improvement:  0
    Has patch:  0                    |                    UI/UX:  0
  Needs tests:  1                    |
Easy pickings:  1                    |
-------------------------------------+-------------------------------------

Comment (by oflores):

 Hi, it seems to be an expected behavior and very well documented. Here it
 is part of the explanation from django doc.

 https://docs.djangoproject.com/en/1.6/topics/db/models/#extra-fields-on-
 many-to-many-relationships

 "Unlike normal many-to-many fields, you can’t use add, create, or
 assignment (i.e., beatles.members = [...]) to create relationships:


 {{{
 # THIS WILL NOT WORK
 >>> beatles.members.add(john)
 # NEITHER WILL THIS
 >>> beatles.members.create(name="George Harrison")
 # AND NEITHER WILL THIS
 >>> beatles.members = [john, paul, ringo, george]
 }}}


 Why? You can’t just create a relationship between a Person and a Group -
 you need to specify all the detail for the relationship required by the
 Membership model. The simple add, create and assignment calls don’t
 provide a way to specify this extra detail. As a result, they are disabled
 for many-to-many relationships that use an intermediate model. The only
 way to create this type of relationship is to create instances of the
 intermediate model."

-- 
Ticket URL: <https://code.djangoproject.com/ticket/21763#comment:3>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-updates+unsubscr...@googlegroups.com.
To post to this group, send email to django-updates@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/067.a9676a86994c204dd212438da20f7d9b%40djangoproject.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to