[ckan-dev] purging revisions

Sean Hammond sean.hammond at okfn.org
Thu Jul 26 12:06:48 UTC 2012


> >> The issue I'm running into is that when I delete and purge a package, I
> >> receive the following errors:
> >> 
> >> Problem purging revision fe09a50b-3f65-4bda-a555-6ba39cf6f3f2:
> >> (IntegrityError) update or delete on table "revision" violates foreign
> >>key
> >> constraint "myextension_group_revision_id_fkey" on table
> >> "myextension_group" DETAIL: Key
> >> (id)=(fe09a50b-3f65-4bda-a555-6ba39cf6f3f2) is still referenced from
> >>table
> >> "myextension_group". 'DELETE FROM revision WHERE revision.id = %(id)s'
> >> {'id': u'fe09a50b-3f65-4bda-a555-6ba39cf6f3f2'}
> >
> >I think it's considered bad practice for extensions to introduce foreign
> >keys against core models, as it causes problems:
> >
> >http://docs.ckan.org/en/latest/writing-extensions.html#libraries-available
> >-to-extensions
> 
> Sean, 
> 
> Thanks for the researched reply.
> 
> What is considered a best practice for my use case?

If I understood your problem correctly, your extension has introduced a
new db table that includes a foreign key constraint against one of
CKAN's core db tables. So if you removed this foreign key constraint it
would work, correct? I'd suggest doing that, and then using Python code
in your extension to impose your foreign key constraint rather than
using an actual SQL constraint. But I'd be interested to know what other
CKAN devs think about this..




More information about the ckan-dev mailing list