Django

Code

Ticket #154 (closed: fixed)

Opened 3 years ago

Last modified 1 year ago

Can't delete object with ManytoMany Relationship

Reported by: Dobbes Assigned to: adrian
Milestone: Component: django.contrib.admin
Version: Keywords:
Cc: Triage Stage: Accepted
Has patch: 0 Needs documentation: 0
Needs tests: 0 Patch needs improvement: 0

Description (Last modified by adrian)

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/dobbes.com/django/core/handlers/modpython.py", line 214, in get_response
    return callback(request, **param_dict)

  File "/home/punteney/dobbes.com/django/views/admin/main.py", line 1057, in delete_stage
    obj.delete()

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

  File "/home/punteney/dobbes.com/django/core/meta.py", line 760, in method_delete
    cursor.execute("DELETE FROM %s WHERE %s=%%s" % (opts.db_table, opts.pk.name), [getattr(self, opts.pk.name)])

  File "/home/punteney/dobbes.com/django/core/db/base.py", 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.

Attachments

Change History

07/30/05 06:06:20 changed 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.

08/01/05 00:43:46 changed by adrian

  • status changed from new to assigned.

08/08/05 12:56:39 changed by jacob

  • milestone set to Version 1.0.

08/09/05 17:44:47 changed by adrian

  • description changed.

08/09/05 17:45:11 changed by adrian

  • description changed.

08/09/05 19:21:42 changed by adrian

  • status changed from assigned to closed.
  • resolution set to fixed.

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

01/17/07 16:12:17 changed by

  • milestone deleted.

Milestone Version 1.0 deleted


Add/Change #154 (Can't delete object with ManytoMany Relationship)




Change Properties
Action