Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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
@adrianholovaty adrianholovaty authored
Showing with 14 additions and 3 deletions.
  1. +14 −3 django/core/management.py
View
17 django/core/management.py
@@ -132,9 +132,20 @@ def get_sql_delete(mod):
pass
else:
output.append("DROP TABLE %s;" % f.get_m2m_db_table(opts))
- output.append("DELETE FROM packages WHERE label = '%s';" % mod._MODELS[0]._meta.app_label)
- output.append("DELETE FROM auth_permissions WHERE package = '%s';" % mod._MODELS[0]._meta.app_label)
- output.append("DELETE FROM content_types WHERE package = '%s';" % mod._MODELS[0]._meta.app_label)
+
+ app_label = mod._MODELS[0]._meta.app_label
+
+ # Delete from packages, auth_permissions, content_types.
+ output.append("DELETE FROM packages WHERE label = '%s';" % app_label)
+ output.append("DELETE FROM auth_permissions WHERE package = '%s';" % app_label)
+ output.append("DELETE FROM content_types WHERE package = '%s';" % app_label)
+
+ # Delete from the admin log.
+ if cursor is not None:
+ cursor.execute("SELECT id FROM content_types WHERE package = %s", [app_label])
+ for row in cursor.fetchall():
+ output.append("DELETE FROM auth_admin_log WHERE content_type_id = %s;" % row[0])
+
return output[::-1] # Reverse it, to deal with table dependencies.
get_sql_delete.help_doc = "Prints the DROP TABLE SQL statements for the given app(s)."
get_sql_delete.args = APP_ARGS
Please sign in to comment.
Something went wrong with that request. Please try again.