I'm having a little trouble with my "through" table. I've set the modal to have two Foreign Key fields. Ex. below:
-- class Person(models.Model):
title = models.CharField(max_length=255)
class Group(models.Model):
title = models.CharField(max_length=255)
members= models.ManyToManyField(Person, through='Membership', through_fields=('group', 'person'))
class Membership(models.Model):
group = models.ForeignKey(Group, on_delete=models.CASCADE)
person = models.ForeignKey(Person, on_delete=models.PROTECT)
I want it to keep the "Person" entries when deleted but if a group is deleted in needs to cascade.
However when looking are the SQL in Postgresql it's created the Membership table constraint for the Group id with "ON DELETE NO ACTION"
CONSTRAINT groups_membership_group_id_d4404a8c_fk_groups_group_id FOREIGN KEY (group_id)
REFERENCES public.groups_group (id) MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION
DEFERRABLE INITIALLY DEFERRED,My understanding was that setting CASCADE on the group in the Membership modal would set ON DELETE CASCADE for the Membership table CREATE?
If it's not a bug and I've missed something, I apologies in advance.
Cheers,
James
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/d489db86-aeea-4272-9fc9-a1d5ffcd3736%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
No comments:
Post a Comment