Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #206 -- 'django-admin sqlclear' now deletes from admin log to p…

…revent referential integrity violations

git-svn-id: http://code.djangoproject.com/svn/django/trunk@323 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit b23c63bcfeb870c46889fbf1d36874017c358c90 1 parent aeff2cb
Adrian Holovaty authored July 26, 2005

Showing 1 changed file with 14 additions and 3 deletions. Show diff stats Hide diff stats

  1. 17  django/core/management.py
17  django/core/management.py
@@ -132,9 +132,20 @@ def get_sql_delete(mod):
132 132
                 pass
133 133
             else:
134 134
                 output.append("DROP TABLE %s;" % f.get_m2m_db_table(opts))
135  
-    output.append("DELETE FROM packages WHERE label = '%s';" % mod._MODELS[0]._meta.app_label)
136  
-    output.append("DELETE FROM auth_permissions WHERE package = '%s';" % mod._MODELS[0]._meta.app_label)
137  
-    output.append("DELETE FROM content_types WHERE package = '%s';" % mod._MODELS[0]._meta.app_label)
  135
+
  136
+    app_label = mod._MODELS[0]._meta.app_label
  137
+
  138
+    # Delete from packages, auth_permissions, content_types.
  139
+    output.append("DELETE FROM packages WHERE label = '%s';" % app_label)
  140
+    output.append("DELETE FROM auth_permissions WHERE package = '%s';" % app_label)
  141
+    output.append("DELETE FROM content_types WHERE package = '%s';" % app_label)
  142
+
  143
+    # Delete from the admin log.
  144
+    if cursor is not None:
  145
+        cursor.execute("SELECT id FROM content_types WHERE package = %s", [app_label])
  146
+        for row in cursor.fetchall():
  147
+            output.append("DELETE FROM auth_admin_log WHERE content_type_id = %s;" % row[0])
  148
+
138 149
     return output[::-1] # Reverse it, to deal with table dependencies.
139 150
 get_sql_delete.help_doc = "Prints the DROP TABLE SQL statements for the given app(s)."
140 151
 get_sql_delete.args = APP_ARGS

0 notes on commit b23c63b

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