# Clear, empty, delete database for another import (development)

**URL:** https://meta.discourse.org/t/clear-empty-delete-database-for-another-import-development/66498
**Category:** Support
**Created:** [July 20, 2017, 10:20am UTC](https://meta.discourse.org/t/clear-empty-delete-database-for-another-import-development/66498 "2017-07-20T10:20:31Z")
**Posts on this page:** 11
**Page:** 1

<div class="post-metadata">

### Author: ![Silvanus](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/silvanus/32/62831_2.png) [@Silvanus](https://meta.discourse.org/u/Silvanus)
#### Post date: [July 20, 2017, 10:20am UTC](https://meta.discourse.org/t/clear-empty-delete-database-for-another-import-development/66498/1 "2017-07-20T10:20:31Z")

</div>

So, I managed to import my age old forum into Discourse, and I madea Discourse backup of it. Later I will put it down in a production environment and make the static archive. Right now I’m on a developoment build. But now I’m running into a problem: I would like to clear out the database and insert my second forum into Discourse, so that the old forum is removed.

I tried a few threads below, but they didn’t give me the answer I need:

[https://meta.discourse.org/t/is-there-a-way-to-clear-out-my-database/23813/](https://meta.discourse.org/t/is-there-a-way-to-clear-out-my-database/23813/)

[https://meta.discourse.org/t/how-to-delete-the-whole-database/23602/](https://meta.discourse.org/t/how-to-delete-the-whole-database/23602/)

I even tried `cd /;sudo find|grep shared/standalone`, but didn’t find the thing to be removed.

Please advise! 🙂

---

<div class="post-metadata">

### Author: ![zogstrip](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/zogstrip/32/512781_2.png) [@zogstrip](https://meta.discourse.org/u/zogstrip)
#### Post date: [July 20, 2017, 10:49am UTC](https://meta.discourse.org/t/clear-empty-delete-database-for-another-import-development/66498/2 "2017-07-20T10:49:53Z")

</div>

Easiest is to drop the database and create a new one: `rake db:drop db:create db:migrate`.

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [July 20, 2017, 12:52pm UTC](https://meta.discourse.org/t/clear-empty-delete-database-for-another-import-development/66498/3 "2017-07-20T12:52:12Z")

</div>

It’s probably also a good idea to remove uploads:

```
   rm -fr public/uploads

```

I once leaked a load of virus-infected uploads from one site I imported to another client. :sadpanda:

[Here](https://gist.github.com/pfaffman/441774b4d73bd180869cb306ffcebb0b) is a gist of my `new_discourse_database` script that kills any running rubies (you can’t drop the database if `rails s` is running), deletes uploads, makes the new database, and sets an admin user and password. It also prints an obnoxious warning and waits 5 seconds since I’ve run it by mistake a few times too many.

---

<div class="post-metadata">

### Author: ![Silvanus](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/silvanus/32/62831_2.png) [@Silvanus](https://meta.discourse.org/u/Silvanus)
#### Post date: [July 20, 2017, 6:50pm UTC](https://meta.discourse.org/t/clear-empty-delete-database-for-another-import-development/66498/4 "2017-07-20T18:50:03Z")

</div>

I only have the dump, so this is not an issue

---

<div class="post-metadata">

### Author: ![Silvanus](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/silvanus/32/62831_2.png) [@Silvanus](https://meta.discourse.org/u/Silvanus)
#### Post date: [July 23, 2017, 10:20pm UTC](https://meta.discourse.org/t/clear-empty-delete-database-for-another-import-development/66498/5 "2017-07-23T22:20:25Z")

</div>

After running `bundle exec rake db:drop db:create db:migrate` I get the following error:

```
== Seed from /home/jsilvanus/discourse/db/fixtures/500_lounge_category.rb
rake aborted!
ActiveRecord::StatementInvalid: PG::UndefinedColumn: ERROR: column groups.visible does not exist
LINE 1: ...AS t1_r22, "groups"."visibility_level" AS t1_r23, "groups"."...
                                                             ^
: SELECT "category_groups"."id" AS t0_r0, "category_groups"."category_id" AS t0_r1, "category_groups"."group_id" AS t0_r2, "category_groups"."created_at" AS t0_r3, "category_groups"."updated_at" AS t0_r4, "category_groups"."permission_type" AS t0_r5, "groups"."id" AS t1_r0, "groups"."name" AS t1_r1, "groups"."created_at" AS t1_r2, "groups"."updated_at" AS t1_r3, "groups"."automatic" AS t1_r4, "groups"."user_count" AS t1_r5, "groups"."alias_level" AS t1_r6, "groups"."automatic_membership_email_domains" AS t1_r7, "groups"."automatic_membership_retroactive" AS t1_r8, "groups"."primary_group" AS t1_r9, "groups"."title" AS t1_r10, "groups"."grant_trust_level" AS t1_r11, "groups"."incoming_email" AS t1_r12, "groups"."has_messages" AS t1_r13, "groups"."flair_url" AS t1_r14, "groups"."flair_bg_color" AS t1_r15, "groups"."flair_color" AS t1_r16, "groups"."bio_raw" AS t1_r17, "groups"."bio_cooked" AS t1_r18, "groups"."public" AS t1_r19, "groups"."allow_membership_requests" AS t1_r20, "groups"."full_name" AS t1_r21, "groups"."default_notification_level" AS t1_r22, "groups"."visibility_level" AS t1_r23, "groups"."visible" AS t1_r24 FROM "category_groups" INNER JOIN "groups" ON "groups"."id" = "category_groups"."group_id" WHERE "category_groups"."category_id" = 2 ORDER BY groups.name
/home/jsilvanus/discourse/app/serializers/category_serializer.rb:24:in `group_permissions'
/home/jsilvanus/discourse/app/serializers/category_serializer.rb:38:in `available_groups'
(eval):28:in `_fast_attributes'
/home/jsilvanus/discourse/app/models/category.rb:259:in `publish_category'
(eval):11:in `block (3 levels) in run_file'
(eval):9:in `block (2 levels) in run_file'
/home/jsilvanus/discourse/lib/tasks/db.rake:8:in `block in <main>'
/home/jsilvanus/.rbenv/versions/2.3.4/bin/bundle:23:in `load'
/home/jsilvanus/.rbenv/versions/2.3.4/bin/bundle:23:in `<main>'
PG::UndefinedColumn: ERROR: column groups.visible does not exist
LINE 1: ...AS t1_r22, "groups"."visibility_level" AS t1_r23, "groups"."...
                                                             ^
/home/jsilvanus/discourse/app/serializers/category_serializer.rb:24:in `group_permissions'
/home/jsilvanus/discourse/app/serializers/category_serializer.rb:38:in `available_groups'
(eval):28:in `_fast_attributes'
/home/jsilvanus/discourse/app/models/category.rb:259:in `publish_category'
(eval):11:in `block (3 levels) in run_file'
(eval):9:in `block (2 levels) in run_file'
/home/jsilvanus/discourse/lib/tasks/db.rake:8:in `block in <main>'
/home/jsilvanus/.rbenv/versions/2.3.4/bin/bundle:23:in `load'
/home/jsilvanus/.rbenv/versions/2.3.4/bin/bundle:23:in `<main>'
NameError: NameError
/home/jsilvanus/discourse/app/models/category.rb:259:in `publish_category'
(eval):11:in `block (3 levels) in run_file'
(eval):9:in `block (2 levels) in run_file'
/home/jsilvanus/discourse/lib/tasks/db.rake:8:in `block in <main>'
/home/jsilvanus/.rbenv/versions/2.3.4/bin/bundle:23:in `load'
/home/jsilvanus/.rbenv/versions/2.3.4/bin/bundle:23:in `<main>'
Tasks: TOP => db:migrate
(See full trace by running task with --trace)

```

I ran `db:drop` and `db:craete` separately as well, they went fine. `db:migrate` gives the fail.

---

<div class="post-metadata">

### Author: ![gerhard](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/gerhard/32/119479_2.png) [@gerhard](https://meta.discourse.org/u/gerhard)
#### Post date: [July 23, 2017, 10:57pm UTC](https://meta.discourse.org/t/clear-empty-delete-database-for-another-import-development/66498/6 "2017-07-23T22:57:50Z")

</div>

I ran into the same problem today. Quick workaround: Call `db:migrate` twice.

---

<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: [October 9, 2017, 7:34am UTC](https://meta.discourse.org/t/clear-empty-delete-database-for-another-import-development/66498/7 "2017-10-09T07:34:22Z")

</div>

Hi, we had a user field which has been removed during time. but some users has already filled it. **Is there anyway to remove or clear those entries from the database?**

the reason I want to remove it, is that It’s annoying some of our old users, as they can’t change the field anymore.

I’ve already tried to explain the problem here:

[https://meta.discourse.org/t/removed-user-fileds-are-still-shown-in-user-profile-page/71344?u=pad\_pors](https://meta.discourse.org/t/removed-user-fileds-are-still-shown-in-user-profile-page/71344)

---

<div class="post-metadata">

### Author: ![007](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/007/32/175794_2.png) [@007](https://meta.discourse.org/u/007)
#### Post date: [April 16, 2020, 10:01pm UTC](https://meta.discourse.org/t/clear-empty-delete-database-for-another-import-development/66498/8 "2020-04-16T22:01:49Z")

</div>

I’m trying to delete a database that I’m using to test an import as well, but running the following command didn’t delete anything:

`bundle exec rake db:drop db:create db:migrate`

When I refresh, I still see all the data from the previous import.

Is there anything else I need to do to complete wipe and rebuild the database so I can go through setup again and/or attempt another import?

---

<div class="post-metadata">

### Author: ![pgr](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pgr/32/156783_2.png) [@pgr](https://meta.discourse.org/u/pgr)
#### Post date: [April 17, 2020, 9:04am UTC](https://meta.discourse.org/t/clear-empty-delete-database-for-another-import-development/66498/9 "2020-04-17T09:04:01Z")

</div>

Have a look here

> [@DB Ownership / Wiping out Production](https://meta.discourse.org/t/db-ownership-wiping-out-production/113534/12):
>
> Just to leave some feedback here, since I had to re-do this today. What eventually worked for me is to delete the full /docker-app/standalone directory no need to stop the container, the next command includes that in its script run ./launcher rebuild app the rebuild took about 10 minutes and included an update to the code by pulling it from GitHub. I had some trouble on my next step, so I’ll also document it here in case it’s useful for someone. I needed to create a privileged database user …

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [April 17, 2020, 10:07pm UTC](https://meta.discourse.org/t/clear-empty-delete-database-for-another-import-development/66498/10 "2020-04-17T22:07:12Z")

</div>

I find it easier to make a backup just after setting up the site and then restoring it.

---

<div class="post-metadata">

### Author: ![JammyDodger](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jammydodger/32/254611_2.png) [@JammyDodger](https://meta.discourse.org/u/JammyDodger)
#### Post date: [June 8, 2024, 12:37pm UTC](https://meta.discourse.org/t/clear-empty-delete-database-for-another-import-development/66498/11 "2024-06-08T12:37:04Z")

</div>

This topic was automatically closed after 2515 days. New replies are no longer allowed.
