#23673: IntegrityError when using a ManyToMany relation to add a model instance with unique constraint. -------------------------------------+------------------------------------- Reporter: jo-soft | Owner: nobody Type: Bug | Status: new Component: Database layer | Version: 1.7 (models, ORM) | Keywords: ManyToManyField, Severity: Normal | get_or_create Triage Stage: Unreviewed | Has patch: 0 Easy pickings: 0 | UI/UX: 0 -------------------------------------+------------------------------------- Setting: - two models connected with a m2m relation. (let's call them m1, m2 and the ralation m1.m2m) - one of them has a unique relation on one field. (lets say field1) - creating instances of m2 via m1.m2m.get_or_create works only once for every unique value of field1. independent of the instance of m1.
The get parts tries to get an instance of m2 which is related to m1, which does not exists. this leads to creating a new instance of m2 with field equals the value used above. this already exists and leads to a IntegrityError. See this minimal example: http://pastebin.com/eUs1R6fD -- Ticket URL: <https://code.djangoproject.com/ticket/23673> 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/050.c09e7b7e884dbadb0c58b0ffc9c3e1d0%40djangoproject.com. For more options, visit https://groups.google.com/d/optout.