# Troubles executing import/migration scripts

**URL:** https://meta.discourse.org/t/troubles-executing-import-migration-scripts/240473
**Category:** Migration
**Created:** [September 30, 2022, 10:24am UTC](https://meta.discourse.org/t/troubles-executing-import-migration-scripts/240473 "2022-09-30T10:24:04Z")
**Posts on this page:** 10
**Page:** 1

<div class="post-metadata">

### Author: ![Maight723](https://avatars.discourse-cdn.com/v4/letter/m/e99b99/32.png) [@Maight723](https://meta.discourse.org/u/Maight723)
#### Post date: [September 30, 2022, 10:24am UTC](https://meta.discourse.org/t/troubles-executing-import-migration-scripts/240473/1 "2022-09-30T10:24:04Z")

</div>

I have successfully migrated a forum to Disourcse with a custom script before, but now when I execute it again, I get the following import error:

```plaintext
/var/www/discourse/vendor/bundle/ruby/2.7.0/gems/activerecord-7.0.3.1/lib/active_record/connection_adapters/postgresql_adapter.rb:81:in `rescue in new_client': We could not find your database: discourse. Which can be found in the database configuration file located at config/database.yml. (ActiveRecord::NoDatabaseError)

To resolve this issue:

- Did you create the database for this app, or delete it? You may need to create your database.
- Has the database name changed? Check your database.yml config has the correct database name.

To create your database, run:

        bin/rails db:create

```

The following import in my script fails:

```plaintext
require File.expand_path(File.dirname( __FILE__ ) + "/base.rb")

```

I execute the script with

```plaintext
./launcher enter app
cd /var/www/discourse
bundle exec ruby script/import_scripts/avatar.rb

```

I don’t really understand the error though: I can access the database through `sudo -u postgres psql discourse`, validating that the database “discourse” does exist. Also, the website is running fine. When I open `rails c` I can also access the data.

Can you give me some pointers what’s messed up there?

---

<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: [September 30, 2022, 10:26am UTC](https://meta.discourse.org/t/troubles-executing-import-migration-scripts/240473/2 "2022-09-30T10:26:38Z")

</div>

Discourse can’t find its database. So you need to fix that. Was this a [standard install](https://meta.discourse.org/t/142537?silent=true) or a development install? Have a look at the appropriate guide and make discourse work as the first step.

---

<div class="post-metadata">

### Author: ![Maight723](https://avatars.discourse-cdn.com/v4/letter/m/e99b99/32.png) [@Maight723](https://meta.discourse.org/u/Maight723)
#### Post date: [September 30, 2022, 10:44am UTC](https://meta.discourse.org/t/troubles-executing-import-migration-scripts/240473/3 "2022-09-30T10:44:50Z")

</div>

[Standard install](https://meta.discourse.org/t/142537?silent=true), following [discourse/docs/INSTALL-cloud.md at main · discourse/discourse · GitHub](https://github.com/discourse/discourse/blob/main/docs/INSTALL-cloud.md)

The only thing I did (that I can think of now) since it was working last time was reverting to backups.

What confuses me about the error is that everything else works. The site works perfectly fine. Only the import script fails.

---

<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: [September 30, 2022, 10:51am UTC](https://meta.discourse.org/t/troubles-executing-import-migration-scripts/240473/4 "2022-09-30T10:51:17Z")

</div>

> [@Maight723](#):
>
> The site works perfectly fine

And you’re running they script inside the container?

---

<div class="post-metadata">

### Author: ![Maight723](https://avatars.discourse-cdn.com/v4/letter/m/e99b99/32.png) [@Maight723](https://meta.discourse.org/u/Maight723)
#### Post date: [September 30, 2022, 10:53am UTC](https://meta.discourse.org/t/troubles-executing-import-migration-scripts/240473/5 "2022-09-30T10:53:21Z")

</div>

Yes, I use `./launcher enter app` and I have only one configuration (app).

---

<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: [September 30, 2022, 11:03am UTC](https://meta.discourse.org/t/troubles-executing-import-migration-scripts/240473/6 "2022-09-30T11:03:48Z")

</div>

Oh. Sorry. You said all of that in the OP;I didn’t read very well!

I can’t think of an explanation. Maybe reboot?

---

<div class="post-metadata">

### Author: ![Maight723](https://avatars.discourse-cdn.com/v4/letter/m/e99b99/32.png) [@Maight723](https://meta.discourse.org/u/Maight723)
#### Post date: [September 30, 2022, 11:47am UTC](https://meta.discourse.org/t/troubles-executing-import-migration-scripts/240473/7 "2022-09-30T11:47:52Z")

</div>

I did reboot and it didn’t fix the issue. I now also encounter the same issue on my local machine (local docker)… which makes me think that somehow I run the command somehow incorrectly…

And thank you – I celebrate the swiftness of your responses and the support!

---

<div class="post-metadata">

### Author: ![Maight723](https://avatars.discourse-cdn.com/v4/letter/m/e99b99/32.png) [@Maight723](https://meta.discourse.org/u/Maight723)
#### Post date: [September 30, 2022, 12:09pm UTC](https://meta.discourse.org/t/troubles-executing-import-migration-scripts/240473/8 "2022-09-30T12:09:10Z")

</div>

Yes, now I got it. I executed the script as `root`, but not as user `discourse`:

```plaintext
./launcher enter app
cd /var/www/discourse
su discourse
bundle exec ruby script/import_scripts/import.rb

```

Thanks for the support @pfaffman \<3

---

<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: [September 30, 2022, 1:33pm UTC](https://meta.discourse.org/t/troubles-executing-import-migration-scripts/240473/9 "2022-09-30T13:33:40Z")

</div>

Hmm. Perhaps something had changed, as I’m site that I’ve not been running import scripts as used discourse. Good work!

---

<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: [October 30, 2022, 1:34pm UTC](https://meta.discourse.org/t/troubles-executing-import-migration-scripts/240473/10 "2022-10-30T13:34:24Z")

</div>

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