Opened 7 years ago

Closed 7 years ago

Last modified 4 years ago

#10770 closed (duplicate)

IntegrityError when creating multiple inline objects with ForeignKey and unique_together

Reported by: rutt Owned by: nobody
Component: contrib.admin Version: 1.1-beta
Severity: Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:


Using the models below, enter two Attachment objects with the same slug on the Parent change page, and then save. The result is an IntegrityError where "columns parent_id, slug are not unique". If the two Attachment objects are created and saved individually, the admin shows the expected form error: "Attachment with this Parent and Slug already exists."


class Parent(models.Model):
    name = models.CharField(max_length=200)
class Attachment(models.Model):
    name = models.CharField(max_length=200)
    parent = models.ForeignKey(Parent)
    slug = models.SlugField()
    class Meta:
        unique_together = ['parent', 'slug']


class ParentAdmin(admin.ModelAdmin):
    inlines = [AttachmentInline], admin.ModelAdmin), ParentAdmin)

Change History (3)

comment:1 Changed 7 years ago by rutt

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

See also #10769

comment:2 Changed 7 years ago by mrts

  • Resolution set to duplicate
  • Status changed from new to closed

Duplicate of #9493 .

comment:3 Changed 4 years ago by jacob

  • milestone 1.1 deleted

Milestone 1.1 deleted

Note: See TracTickets for help on using tickets.
Back to Top