Opened 14 years ago

Closed 14 years ago

Last modified 6 years ago

#154 closed defect (fixed)

Can't delete object with ManytoMany Relationship

Reported by: Dobbes Owned by: Adrian Holovaty
Component: contrib.admin Version:
Severity: normal Keywords:
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Adrian Holovaty)

If you have an object with a manytomany relationship you can't delete it within the admin interface. As it spits out this error.

Traceback (most recent call last):

  File "/home/punteney/", line 214, in get_response
    return callback(request, **param_dict)

  File "/home/punteney/", line 1057, in delete_stage

  File "/home/punteney/", line 57, in _curried
    return args[0](*(args[1:]+moreargs), **dict(kwargs.items() + morekwargs.items()))

  File "/home/punteney/", line 760, in method_delete
    cursor.execute("DELETE FROM %s WHERE %s=%%s" % (opts.db_table,, [getattr(self,])

  File "/home/punteney/", line 10, in execute
    result = self.cursor.execute(sql, params)

IntegrityError: ERROR:  update or delete on "blog_entries" violates foreign key constraint "$1" on "blog_entries_categories"
DETAIL:  Key (id)=(2) is still referenced from table "blog_entries_categories".

DELETE FROM blog_entries WHERE id=2

This is from trying to delete a blog entry that is tied to the categories. The line in the Entry model is:

meta.ManyToManyField(Category, filter_interface=meta.HORIZONTAL),

I can't remove the category linking before I delete it as it is a required field so it comes back with an error message saying that the field is required.

Change History (8)

comment:1 Changed 14 years ago by nichyoung

This problem manifests in the core flatfiles interface - you can't delete a flatfile as it must contain a many to many reference to a site.

comment:2 Changed 14 years ago by Adrian Holovaty

Status: newassigned

comment:3 Changed 14 years ago by Jacob

milestone: Version 1.0

comment:4 Changed 14 years ago by Adrian Holovaty

Description: modified (diff)

comment:5 Changed 14 years ago by Adrian Holovaty

Description: modified (diff)

comment:6 Changed 14 years ago by Adrian Holovaty

Resolution: fixed
Status: assignedclosed

(In [447]) Fixed #154 -- Fixed constraint error when deleting an object with a many-to-many field

comment:7 Changed 12 years ago by (none)

milestone: Version 1.0

Milestone Version 1.0 deleted

comment:8 Changed 6 years ago by anonymous

Easy pickings: unset
UI/UX: unset

use remove

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