Guest User

M2M Bug?

a guest
Oct 17th, 2014
358
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.42 KB | None | 0 0
  1. class M1(models.Model):
  2.     m2m = models.ManyToManyField(m2)
  3.  
  4. class M2(models.Model):
  5.     name = models.CharField(unique=True)
  6.  
  7. ---
  8.  
  9. m = M1.create()
  10. # this passes
  11. m.m2m.get_or_create(name='foo')
  12.  
  13. an_other_m = M1.create()
  14. # and now this fails:
  15. an_other_m.m2m.get_or_create(name='foo')
  16.  
  17. #IntegrityError: duplicate key value violates unique constraint "test_m2_name_key"
  18. #DETAIL:  Key (name)=(foo) already exists.
Advertisement
Add Comment
Please, Sign In to add comment