Hi,

I know that Django's default behaviour on ForeignKey is ON DELETE CASCADE 
(unless you set on_delete to PROTECT). However, I wasn't sure how this 
extended to ManyToManyFields.

I've just tested with one of my own applications - I have an "Article" 
object, with m2m to a "Journalist" object. Deleting either end of the m2m 
didn't affect the other end.

I assume this is intended behaviour - since it simply cascades to the 
invisible join table in the middle, but through to the other actual end of 
the relatinoship?

However, the issue I see with this is that if the m2m can't be empty (as is 
default). You delete one end, and everything seems fine and dandy. But then 
you go into edit the other end of the relationship, and it now complains 
that the m2m field is empty. But during that period until you tried to 
open/edit it, it was fine with having a empty mandatory m2m field. Surely 
there's an integrity issue there?

Secondly, is there a way to tweak the ON DELETE behaviour for m2m. E.g. can 
you set it to PROTECT, just like you do for FK's, to prevent you deleting an 
object, if something else has a m2m link to it? Or can you set it to ON 
CASCADE DELETE, as it does for FK?

Cheers,
Victor

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to