Fix ontology re-loading to work with foreign keys

Previous we've had to add a hack when re-loading ontology terms to disable
foreign key checking (using an SQLite PRAGMA).  This is fixed now by delete
terms in the right order before re-loading.