# Migration error with question2answer.rb

**URL:** https://meta.discourse.org/t/migration-error-with-question2answer-rb/110601
**Category:** Migration
**Created:** [March 4, 2019, 8:26am UTC](https://meta.discourse.org/t/migration-error-with-question2answer-rb/110601 "2019-03-04T08:26:58Z")
**Posts on this page:** 20
**Page:** 1

<div class="post-metadata">

### Author: ![Ankhamax](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/ankhamax/32/52785_2.png) [@Ankhamax](https://meta.discourse.org/u/Ankhamax)
#### Post date: [March 4, 2019, 8:26am UTC](https://meta.discourse.org/t/migration-error-with-question2answer-rb/110601/1 "2019-03-04T08:26:58Z")

</div>

Hi there,

I am trying to use [question2answer.rb](https://github.com/discourse/discourse/blob/master/script/import_scripts/question2answer.rb) importer script to migrate my site to the discourse platform. But I am facing the following error during the migration process.

How to fix it? 🤔 I am using the default docker container on a clean ubuntu 18.04.

```
importing users

**Traceback** (most recent call last):

9: from script/import_scripts/question2answer.rb:560:in `&lt;main&gt;'

8: from /var/www/discourse/script/import_scripts/base.rb:47:in `perform'

7: from script/import_scripts/question2answer.rb:71:in `execute'

6: from script/import_scripts/question2answer.rb:85:in `import_users'

5: from script/import_scripts/question2answer.rb:555:in `mysql_query'

4: from /var/www/discourse/vendor/bundle/ruby/2.5.0/gems/rack-mini-profiler-1.0.2/lib/patches/db/mysql2.rb:22:in `query'

3: from /var/www/discourse/vendor/bundle/ruby/2.5.0/gems/mysql2-0.5.2/lib/mysql2/client.rb:130:in `query'

2: from /var/www/discourse/vendor/bundle/ruby/2.5.0/gems/mysql2-0.5.2/lib/mysql2/client.rb:130:in `handle_interrupt'

1: from /var/www/discourse/vendor/bundle/ruby/2.5.0/gems/mysql2-0.5.2/lib/mysql2/client.rb:131:in `block in query'

/var/www/discourse/vendor/bundle/ruby/2.5.0/gems/mysql2-0.5.2/lib/mysql2/client.rb:131:in `_query': **Table 'primary_db.users' doesn't exist (**  **Mysql2::Error** **)**

```

---

<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: [March 4, 2019, 12:06pm UTC](https://meta.discourse.org/t/migration-error-with-question2answer-rb/110601/2 "2019-03-04T12:06:00Z")

</div>

The users table that it’s looking for does not exist. Do you see a table called “users”? Do you have the right database?

---

<div class="post-metadata">

### Author: ![Ankhamax](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/ankhamax/32/52785_2.png) [@Ankhamax](https://meta.discourse.org/u/Ankhamax)
#### Post date: [March 4, 2019, 12:22pm UTC](https://meta.discourse.org/t/migration-error-with-question2answer-rb/110601/3 "2019-03-04T12:22:20Z")

</div>

I believe that I have the right database as I finished importing the database (on Discourse server) using

```
mysql -uroot -p -e 'CREATE DATABASE q2a' 

mysql -uroot -p q2a < q2a_dump.sql

```

I was able to back up my new database using

`mysqldump -u username -p database_to_backup > backup_name.sql`

and I downloaded it on my computer to verify that I have the proper database.

> [@pfaffman](#):
>
> Do you see a table called “users”?

I have a table called qa\_users

---

<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: [March 4, 2019, 12:33pm UTC](https://meta.discourse.org/t/migration-error-with-question2answer-rb/110601/4 "2019-03-04T12:33:39Z")

</div>

That’s the default. Did you change the db\_prefix to “primary\_dB” for some reason?

---

<div class="post-metadata">

### Author: ![Ankhamax](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/ankhamax/32/52785_2.png) [@Ankhamax](https://meta.discourse.org/u/Ankhamax)
#### Post date: [March 4, 2019, 12:39pm UTC](https://meta.discourse.org/t/migration-error-with-question2answer-rb/110601/5 "2019-03-04T12:39:16Z")

</div>

It was already included in the importer script as follows.

```
  # CHANGE THESE BEFORE RUNNING THE IMPORTER

  DB_HOST ||= ENV['DB_HOST'] || "localhost"
  DB_NAME ||= ENV['DB_NAME']
  DB_PW ||= ENV['DB_PW']
  DB_USER ||= ENV['DB_USER']
  TIMEZONE ||= ENV['TIMEZONE'] || "America/Los_Angeles"
  TABLE_PREFIX ||= ENV['TABLE_PREFIX'] || "qa_"
  MAIN_APP_DB_NAME = "primary_db"

```

So I didn’t change MAIN\_APP\_DB\_NAME part as I am not familiar with that.

---

<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: [March 4, 2019, 12:44pm UTC](https://meta.discourse.org/t/migration-error-with-question2answer-rb/110601/6 "2019-03-04T12:44:06Z")

</div>

Did you set those environment variables? DB\_NAME TABLE\_PREFIX and so on?

---

<div class="post-metadata">

### Author: ![Ankhamax](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/ankhamax/32/52785_2.png) [@Ankhamax](https://meta.discourse.org/u/Ankhamax)
#### Post date: [March 4, 2019, 1:01pm UTC](https://meta.discourse.org/t/migration-error-with-question2answer-rb/110601/7 "2019-03-04T13:01:29Z")

</div>

> [@Ankhamax](#):
>
> DB\_HOST ||= ENV[‘DB\_HOST’] || “localhost”  
> DB\_NAME ||= ENV[‘DB\_NAME’]  
> DB\_PW ||= ENV[‘DB\_PW’]  
> DB\_USER ||= ENV[‘DB\_USER’]  
> TIMEZONE ||= ENV[‘TIMEZONE’] || “America/Los\_Angeles”  
> TABLE\_PREFIX ||= ENV[‘TABLE\_PREFIX’] || “qa\_”

I set all environment variables that I quoted above.

---

<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: [March 4, 2019, 1:25pm UTC](https://meta.discourse.org/t/migration-error-with-question2answer-rb/110601/8 "2019-03-04T13:25:21Z")

</div>

What did you set TABLE\_PREFIX to?

---

<div class="post-metadata">

### Author: ![Ankhamax](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/ankhamax/32/52785_2.png) [@Ankhamax](https://meta.discourse.org/u/Ankhamax)
#### Post date: [March 4, 2019, 1:28pm UTC](https://meta.discourse.org/t/migration-error-with-question2answer-rb/110601/9 "2019-03-04T13:28:40Z")

</div>

export TABLE\_PREFIX=“qa\_”

---

<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: [March 4, 2019, 1:38pm UTC](https://meta.discourse.org/t/migration-error-with-question2answer-rb/110601/10 "2019-03-04T13:38:20Z")

</div>

Sorry. I’m in my logins and didn’t read the code carefully.

I’m pretty sure that I wrote that script, but I didn’t see that main all stuff down in the query; I’m sure I didn’t write that.

You’ll need to edit the script to have it use the database and prefix that you set in the environment variables.

---

<div class="post-metadata">

### Author: ![Ankhamax](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/ankhamax/32/52785_2.png) [@Ankhamax](https://meta.discourse.org/u/Ankhamax)
#### Post date: [March 4, 2019, 1:49pm UTC](https://meta.discourse.org/t/migration-error-with-question2answer-rb/110601/11 "2019-03-04T13:49:44Z")

</div>

> [@Ankhamax](#):
>
> MAIN\_APP\_DB\_NAME = “primary\_db”

What should I do about this one?

---

<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: [March 4, 2019, 3:05pm UTC](https://meta.discourse.org/t/migration-error-with-question2answer-rb/110601/12 "2019-03-04T15:05:00Z")

</div>

You’ll need to rewrite all of the dB queries.

---

<div class="post-metadata">

### Author: ![Ankhamax](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/ankhamax/32/52785_2.png) [@Ankhamax](https://meta.discourse.org/u/Ankhamax)
#### Post date: [March 5, 2019, 3:21am UTC](https://meta.discourse.org/t/migration-error-with-question2answer-rb/110601/13 "2019-03-05T03:21:10Z")

</div>

> [@pfaffman](#):
>
> You’ll need to rewrite all of the dB queries.

I am sorry, Jay. I am not quite sure what you mean by that? Could you please give me some pointers here? I hope that you don’t mean by rewriting the importer script of question2answer.

Thanks

---

<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: [March 5, 2019, 4:54am UTC](https://meta.discourse.org/t/migration-error-with-question2answer-rb/110601/14 "2019-03-05T04:54:51Z")

</div>

Not the whole script, just the database queries, and really just the FROM part. If you have a budget I can fix it for you.

---

<div class="post-metadata">

### Author: ![Ankhamax](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/ankhamax/32/52785_2.png) [@Ankhamax](https://meta.discourse.org/u/Ankhamax)
#### Post date: [March 5, 2019, 6:00am UTC](https://meta.discourse.org/t/migration-error-with-question2answer-rb/110601/15 "2019-03-05T06:00:09Z")

</div>

I don’t have much budget but I would like to import small data from my old forum.

> [@pfaffman](#):
>
> If you have a budget I can fix it for you.

What do you have in mind?

---

<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: [March 5, 2019, 4:24pm UTC](https://meta.discourse.org/t/migration-error-with-question2answer-rb/110601/16 "2019-03-05T16:24:56Z")

</div>

Send an email to [support@literatecomputing.com](mailto:support@literatecomputing.com).

If I can log in remotely to the machine where you’re running the import it’ll help, as I’ll be able to see whether it works without sending it to you, having you import, tell me what’s wrong, and trying again.

---

<div class="post-metadata">

### Author: ![michaeld](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/michaeld/32/1594_2.png) [@michaeld](https://meta.discourse.org/u/michaeld)
#### Post date: [March 5, 2019, 9:16pm UTC](https://meta.discourse.org/t/migration-error-with-question2answer-rb/110601/17 "2019-03-05T21:16:10Z")

</div>

It seems the question2answer importer was written for a case where there is an additional set of tables in the database for another app that was integrated with it. That is what the MAIN\_APP\_DB\_NAME refers to.

We have done an import for a standalone q2a site recently and we have a modified version of the script which does not depend on this extra database. @RGJ was going to clean it up and submit it back in the next few weeks.

---

<div class="post-metadata">

### Author: ![RGJ](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/rgj/32/523185_2.png) [@RGJ](https://meta.discourse.org/u/RGJ)
#### Post date: [March 5, 2019, 10:08pm UTC](https://meta.discourse.org/t/migration-error-with-question2answer-rb/110601/18 "2019-03-05T22:08:43Z")

</div>

[Here]([https://gist.github.com/[Communiteq](https://www.communiteq.com)](https://gist.github.com/%5BCommuniteq%5D(https://www.communiteq.com)) (formerly DiscourseHosting)/769eff2014d5482f0ab776de03dc3349) is a gist of our modified importer so you don’t need to wait for me to clean it up, the code is already pretty ok though.

- remove dependency on that other mysterious database which is probably something bespoke
- import comments
- import best answer

---

<div class="post-metadata">

### Author: ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)
#### Post date: [March 5, 2019, 11:13pm UTC](https://meta.discourse.org/t/migration-error-with-question2answer-rb/110601/19 "2019-03-05T23:13:23Z")

</div>

Aw nice, thanks for that 🍻

---

<div class="post-metadata">

### Author: ![Ankhamax](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/ankhamax/32/52785_2.png) [@Ankhamax](https://meta.discourse.org/u/Ankhamax)
#### Post date: [March 6, 2019, 12:37pm UTC](https://meta.discourse.org/t/migration-error-with-question2answer-rb/110601/20 "2019-03-06T12:37:39Z")

</div>

In the recent attempt to migrate small data from my old forum resulted in the following error when I used [modified importer script]([https://gist.github.com/[Communiteq](https://www.communiteq.com)](https://gist.github.com/%5BCommuniteq%5D(https://www.communiteq.com)) (formerly DiscourseHosting)/769eff2014d5482f0ab776de03dc3349) provided by @RGJ.

```
Loading existing groups...

Loading existing users...

Loading existing categories...

Loading existing posts...

Loading existing topics...

importing users

**Traceback** (most recent call last):

11: from script/import_scripts/question2answer.rb:601:in `&lt;main&gt;'

10: from /var/www/discourse/script/import_scripts/base.rb:47:in `perform'

9: from script/import_scripts/question2answer.rb:70:in `execute'

8: from script/import_scripts/question2answer.rb:89:in `import_users'

7: from /var/www/discourse/script/import_scripts/base.rb:881:in `batches'

6: from /var/www/discourse/script/import_scripts/base.rb:881:in `loop'

5: from /var/www/discourse/script/import_scripts/base.rb:882:in `block in batches'

4: from script/import_scripts/question2answer.rb:106:in `block in import_users'

3: from /var/www/discourse/script/import_scripts/base.rb:247:in `create_users'

2: from /var/www/discourse/script/import_scripts/base.rb:247:in `each'

1: from /var/www/discourse/script/import_scripts/base.rb:278:in `block in create_users'

/var/www/discourse/script/import_scripts/base.rb:866:in `print_status': **undefined method `to_f' for #&lt;Mysql2::Result:0x000056370b7c1f80&gt; (**  **NoMethodError** **)**

**Did you mean? to_s**

**to_a**

**to_h**

```

I wonder what seems to be causing this error? 😕

[Next page](https://meta.discourse.org/t/migration-error-with-question2answer-rb/110601.md?page=2)
