﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
206	"Referential integrity violation upon applying output of ""django-admin.py sqlclear"" after admin update"	django@…	Adrian Holovaty	"If you create a new app, and create some objects via the admin interface, entries in ""auth_admin_log"" prevent deletion of the app using django-admin.py sqlclear

How to reproduce:

  1. Create and install new app; it can be entirely trivial, the example I used is shown below.
  1. Add an object in the new app using the admin interface.
  1. Attempt to delete the app from the database using django-admin.py sqlclear and piping the output to psql

Result:

{{{
> django-admin.py sqlclear deletion               
BEGIN;
DELETE FROM content_types WHERE package = 'deletion';
DELETE FROM auth_permissions WHERE package = 'deletion';
DELETE FROM packages WHERE label = 'deletion';
DROP TABLE deletion_dummys;
COMMIT;
> django-admin.py sqlclear deletion | psql djangos
BEGIN
ERROR:  update or delete on ""content_types"" violates foreign key constraint ""$2"" on ""auth_admin_log""
DETAIL:  Key (id)=(21) is still referenced from table ""auth_admin_log"".
ERROR:  current transaction is aborted, commands ignored until end of transaction block
ERROR:  current transaction is aborted, commands ignored until end of transaction block
ERROR:  current transaction is aborted, commands ignored until end of transaction block
COMMIT
}}}

Here's the model used in the above:
{{{
> cat deletion/models/deletion.py
from django.core import meta
class Dummy(meta.Model):
    fields = (meta.CharField('dummy', maxlength=200), )
    admin = meta.Admin(list_display = ('dummy',),)
}}}

Two possible fixes spring to mind:

  1. Extend sqlclear so it also deletes from auth_admin_log.
  1. Remove that foreign key constraint.

The first is perhaps preferable, on the basis that if you're deleting an app, you probably don't care about its history?  OTOH maybe there's an option 3 which would be better.  Anyway..."	defect	closed	Tools		normal	fixed	django-admin.py sqlclear admin integrity		Unreviewed	0	0	0	0	0	0
