Referential integrity violation upon applying output of "django-admin.py sqlclear" after admin update
|Reported by:||Owned by:||Adrian Holovaty|
|Severity:||normal||Keywords:||django-admin.py sqlclear admin integrity|
|Has patch:||no||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
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:
- Create and install new app; it can be entirely trivial, the example I used is shown below.
- Add an object in the new app using the admin interface.
- Attempt to delete the app from the database using django-admin.py sqlclear and piping the output to psql
> 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:
- Extend sqlclear so it also deletes from auth_admin_log.
- 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...