0

When I tried to delete a vocabulary, Drupal timed out and I don't think any or all of the terms in the vocabulary were deleted. How can I delete them manually in the database?

1

Can you run sql queries directly against the database? What makes you think the terms are still there? The vocabulary table contains data about the vocabulary, and you could do a left outer join with term_data to see if there are any "orpaned" terms. So something like (assuming you haven't used a prefix on your drupal database):

SELECT * 
FROM term_data t
LEFT OUTER JOIN vocabulary v
ON t.vid = v.vid
WHERE v.vid IS NULL;

You can do a delete on a join if you need to but I suspect you won't find any orphans.

EDIT:

You should also probably check term_node as well that links terms to nodes. If you're going to run these deletes please back up your database first! Also as these queries are written, the term_node needs to run first.

-- Run this first
DELETE n
FROM term_node n
JOIN term_data t
ON n.tid = t.tid 
LEFT OUTER JOIN vocabulary v
ON t.vid = v.vid
WHERE v.vid IS NULL;

-- Then run this query
DELETE t
FROM term_data t
LEFT OUTER JOIN vocabulary v
ON t.vid = v.vid
WHERE v.vid IS NULL;

Remember to back up your database first!

  • Yes I have access to the database. I got 4k results when I ran your query. How can I delete them now? Also is this the only query that deleting a vocabulary performs? Do I need to do any other cleaning up to mimic deleting a vocab through drupal? – Matthew Hui Dec 5 '11 at 3:59
  • Not sure if you see the edit @glumbo, but did the above help you? – Malks Dec 8 '11 at 8:34
  • Yes that helped. Sorry for not responding earlier – Matthew Hui Dec 10 '11 at 7:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.