How can I delete a tag in development database (on local)?

Continuing the discussion from Manually restoring a Discourse backup for development:

on my local machine, I want to delete a tag in the backup database before restore. how can I do it via console?

1 Like

To delete a tag from the Rails console, try:

t = Tag.find_by_name('<your_tag_name>')

Calling destroy! instead of delete in the last command will clean up all records on the site that are associated with the removed tag.


thanks for your help :blush:

is it possible to delete a tag from a database that hasn’t been running yet? i.e. from a backup, which can’t be restored (because of the duplicated tag problem)?

I hope the question is clear.

If I was doing this myself, I would start by going back to the site that the backup file was created on, delete the tag through the Rails console, then create a new backup file.

If that is not possible, or if it does not solve the duplicate tag issue, you could delete the row from the table by opening a psql terminal on it. Something like:

DELETE FROM tags WHERE name = <your_tag_name>;

My concern with this is that it will not remove usages of the deleted tag from the site’s database in the same way as is done if you use the Rails destroy! command. It might be a good idea to test this out on a copy of the backup file to make sure that it does not break anything.

It might also be a good idea to run a SELECT statement before deleting the tag. That might show the cause of the issue:

SELECT FROM tags WHERE name = <your_tag_name>;
1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.