Opened 12 years ago

Closed 11 years ago

#1320 closed defect (duplicate)

django.views.generic.create_update.delete_object does not handle IntegrityError exception

Reported by: mattimustang@… Owned by: Jacob
Component: Generic views Version: master
Severity: normal Keywords:
Cc: Triage Stage: Design decision needed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:


I'm getting the following exception thrown when I try and delete an object named 'My Company' that is set as the 'organisation' field for another object called 'My Contact'

Shouldn't delete_object handle this better?

IntegrityError at /directory/contacts/3/delete/
ERROR: update or delete on "directory_contacts" violates foreign key constraint "directory_contacts_organisation_id_fkey" on "directory_contacts" DETAIL: Key (id)=(3) is still referenced from table "directory_contacts". DELETE FROM "directory_contacts" WHERE "id"=3

The model that I have is:

class Contact(meta.Model):
    name = meta.CharField(maxlenth=32)
    organisation = meta.ForeignKey('self', null=True, blank=True)

Change History (4)

comment:1 Changed 12 years ago by gugu

whych sql are you using? i have two postgreses - on 7 this occurs, on 8 - not. (fresh-copied db)

comment:2 Changed 11 years ago by Simon G. <dev@…>

Can anyone else confirm this? is it a db(-version) specific issue (as suggested by gugu above)?

comment:3 Changed 11 years ago by Gary Wilson <gary.wilson@…>

Triage Stage: UnreviewedDesign decision needed

comment:4 Changed 11 years ago by Malcolm Tredinnick

Resolution: duplicate
Status: newclosed

The real crux of this has to be solved as part of #2288 -- it's a matter of how to handle errors when cascading delete behaviour varies. I suspect the answer is going to be that the user (developer) is responsible for checking for this when cascading deletes are not enabled, but I'm not sure how that will wash out in the end.

Closing this in favour of #2288.

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