Opened 10 years ago

Closed 10 years ago

#8463 closed (invalid)

force_insert doesn't work with inherited models

Reported by: Nicolas Dietrich Owned by: nobody
Component: Core (Other) Version: master
Severity: Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:


The following testcase describes the problem best:


from django.db import models

class Parent(models.Model):
    something = models.SlugField()

class Daughter(Parent):

Interactive session:

In [1]: from appname.models import Daughter
In [2]: d = Daughter(something='algo')
In [3]:
In [4]: d.something='otra'
In [5]:

results in

IntegrityError: duplicate key value violates unique constraint "appname_daughter_pkey"

Change History (1)

comment:1 Changed 10 years ago by Malcolm Tredinnick

milestone: 1.0
Resolution: invalid
Status: newclosed

That's not a bug, it's exactly the right behaviour. You created d and then you try to save it with updated data (the primary key will still be the same), but say you want to force an insert. The database says the record already exists with that primary key value.

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