Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #154 -- Fixed constraint error when deleting an object with a m…

…any-to-many field

git-svn-id: http://code.djangoproject.com/svn/django/trunk@447 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 991832d0c4dc211a4346256b62c44942894b495d 1 parent fd579f2
Adrian Holovaty authored
3  django/core/meta/__init__.py
@@ -775,6 +775,9 @@ def method_delete(opts, self):
775 775
     for rel_opts, rel_field in opts.get_all_related_many_to_many_objects():
776 776
         cursor.execute("DELETE FROM %s WHERE %s_id=%%s" % (rel_field.get_m2m_db_table(rel_opts),
777 777
             self._meta.object_name.lower()), [getattr(self, opts.pk.name)])
  778
+    for f in opts.many_to_many:
  779
+        cursor.execute("DELETE FROM %s WHERE %s_id=%%s" % (f.get_m2m_db_table(opts), self._meta.object_name.lower()),
  780
+            [getattr(self, opts.pk.name)])
778 781
     cursor.execute("DELETE FROM %s WHERE %s=%%s" % (opts.db_table, opts.pk.name), [getattr(self, opts.pk.name)])
779 782
     db.db.commit()
780 783
     setattr(self, opts.pk.name, None)
11  tests/testapp/models/many_to_many.py
@@ -69,11 +69,18 @@ def __repr__(self):
69 69
 >>> p1.get_article_list(order_by=['headline'])
70 70
 [Django lets you build Web apps easily, NASA uses Python]
71 71
 
72  
-# If we delete an article, its publication won't be able to access it.
  72
+# If we delete a Publication, its Articles won't be able to access it.
  73
+>>> p1.delete()
  74
+>>> publications.get_list()
  75
+[Science News]
  76
+>>> a1 = articles.get_object(pk=1)
  77
+>>> a1.get_publication_list()
  78
+[]
  79
+
  80
+# If we delete an Article, its Publications won't be able to access it.
73 81
 >>> a2.delete()
74 82
 >>> articles.get_list()
75 83
 [Django lets you build Web apps easily]
76 84
 >>> p1.get_article_list(order_by=['headline'])
77 85
 [Django lets you build Web apps easily]
78  
-
79 86
 """

0 notes on commit 991832d

Please sign in to comment.
Something went wrong with that request. Please try again.