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

**URL:** https://meta.discourse.org/t/how-can-i-delete-a-tag-in-development-database-on-local/161797
**Category:** Support
**Created:** [August 23, 2020, 6:53am UTC](https://meta.discourse.org/t/how-can-i-delete-a-tag-in-development-database-on-local/161797 "2020-08-23T06:53:26Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Pad\_Pors](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pad_pors/32/52016_2.png) [@Pad\_Pors](https://meta.discourse.org/u/Pad_Pors)
#### Post date: [August 23, 2020, 6:53am UTC](https://meta.discourse.org/t/how-can-i-delete-a-tag-in-development-database-on-local/161797/1 "2020-08-23T06:53:27Z")

</div>

Continuing the discussion from [Manually restoring a Discourse backup for development](https://meta.discourse.org/t/manually-restoring-a-discourse-backup-for-development/33551):

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

---

<div class="post-metadata">

### Author: ![simon](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/simon/32/339122_2.png) [@simon](https://meta.discourse.org/u/simon)
#### Post date: [August 24, 2020, 5:07pm UTC](https://meta.discourse.org/t/how-can-i-delete-a-tag-in-development-database-on-local/161797/2 "2020-08-24T17:07:07Z")

</div>

To delete a tag from the Rails console, try:

```plaintext
t = Tag.find_by_name('<your_tag_name>')
t.destroy!

```

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

---

<div class="post-metadata">

### Author: ![Pad\_Pors](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pad_pors/32/52016_2.png) [@Pad\_Pors](https://meta.discourse.org/u/Pad_Pors)
#### Post date: [August 24, 2020, 8:37pm UTC](https://meta.discourse.org/t/how-can-i-delete-a-tag-in-development-database-on-local/161797/3 "2020-08-24T20:37:50Z")

</div>

thanks for your help 😊

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.

---

<div class="post-metadata">

### Author: ![simon](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/simon/32/339122_2.png) [@simon](https://meta.discourse.org/u/simon)
#### Post date: [August 24, 2020, 9:00pm UTC](https://meta.discourse.org/t/how-can-i-delete-a-tag-in-development-database-on-local/161797/4 "2020-08-24T21:00:29Z")

</div>

> [@Pad\_Pors](#):
>
> 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)?

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:

```plaintext
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:

```sql
SELECT FROM tags WHERE name = <your_tag_name>;

```

---

<div class="post-metadata">

### Author: ![system](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/system/32/443519_2.png) [@system](https://meta.discourse.org/u/system)
#### Post date: [September 23, 2020, 9:02pm UTC](https://meta.discourse.org/t/how-can-i-delete-a-tag-in-development-database-on-local/161797/5 "2020-09-23T21:02:20Z")

</div>

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