Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class M1(models.Model):
- m2m = models.ManyToManyField(m2)
- class M2(models.Model):
- name = models.CharField(unique=True)
- ---
- m = M1.create()
- # this passes
- m.m2m.get_or_create(name='foo')
- an_other_m = M1.create()
- # and now this fails:
- an_other_m.m2m.get_or_create(name='foo')
- #IntegrityError: duplicate key value violates unique constraint "test_m2_name_key"
- #DETAIL: Key (name)=(foo) already exists.
Advertisement
Add Comment
Please, Sign In to add comment