# How to troubleshoot database errors in an outdated plugin?

**URL:** https://meta.discourse.org/t/how-to-troubleshoot-database-errors-in-an-outdated-plugin/297339
**Category:** Development
**Created:** [February 29, 2024, 10:08pm UTC](https://meta.discourse.org/t/how-to-troubleshoot-database-errors-in-an-outdated-plugin/297339 "2024-02-29T22:08:23Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![zibetnu](https://avatars.discourse-cdn.com/v4/letter/z/54ee81/32.png) [@zibetnu](https://meta.discourse.org/u/zibetnu)
#### Post date: [February 29, 2024, 10:08pm UTC](https://meta.discourse.org/t/how-to-troubleshoot-database-errors-in-an-outdated-plugin/297339/1 "2024-02-29T22:08:23Z")

</div>

I’m new to Discourse plugin development, and to start off I’m trying to update this [quiz plugin](https://github.com/graydenshand/discourse-quiz) to work with the latest version of Discourse.

If it’s not too much trouble, I could use some help understanding how to troubleshoot this error that comes up whenever I try to make or view a topic while the plugin is enabled:

```plaintext
Message

Job exception: PG::UndefinedTable: ERROR: relation "quizzes" does not exist
LINE 9: WHERE a.attrelid = '"quizzes"'::regclass
                            ^

Backtrace

rack-mini-profiler-3.3.0/lib/patches/db/pg.rb:110:in `exec'
rack-mini-profiler-3.3.0/lib/patches/db/pg.rb:110:in `async_exec'
activerecord-7.0.8/lib/active_record/connection_adapters/postgresql/database_statements.rb:19:in `block (2 levels) in query'
activesupport-7.0.8/lib/active_support/concurrency/share_lock.rb:187:in `yield_shares'
activesupport-7.0.8/lib/active_support/dependencies/interlock.rb:41:in `permit_concurrent_loads'
activerecord-7.0.8/lib/active_record/connection_adapters/postgresql/database_statements.rb:18:in `block in query'
activesupport-7.0.8/lib/active_support/concurrency/load_interlock_aware_monitor.rb:25:in `handle_interrupt'
activesupport-7.0.8/lib/active_support/concurrency/load_interlock_aware_monitor.rb:25:in `block in synchronize'
activesupport-7.0.8/lib/active_support/concurrency/load_interlock_aware_monitor.rb:21:in `handle_interrupt'
activesupport-7.0.8/lib/active_support/concurrency/load_interlock_aware_monitor.rb:21:in `synchronize'

```

Are there any common problems I should look for that might be why the relation doesn’t exist? Would those problems typically be found in in /db?

In case it’s relevant: I’m using the Docker dev environment on Linux as described in this [guide](https://meta.discourse.org/t/install-discourse-for-development-using-docker/102009) and you can see what I’ve done so far [here](https://github.com/zibetnu/discourse-quiz/tree/fix-outdated).

---

<div class="post-metadata">

### Author: ![merefield](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/merefield/32/176214_2.png) [@merefield](https://meta.discourse.org/u/merefield)
#### Post date: [February 29, 2024, 10:10pm UTC](https://meta.discourse.org/t/how-to-troubleshoot-database-errors-in-an-outdated-plugin/297339/2 "2024-02-29T22:10:21Z")

</div>

> [@zibetnu](#):
>
> `PG::UndefinedTable: ERROR: relation "quizzes" does not exist`

Looks like you haven’t run migrations

You need an extra environment variable to run them for plugins, see:

> [@Error when running plugin specs](https://meta.discourse.org/t/error-when-running-plugin-specs/274701/2):
>
> Looking at the test database, the chat migrations appear not to have run. \> psql discourse\_test # \d Oh …! I forgot to add the first environment variable to include plugins with this db migration (because chat is still a plugin): LOAD\_PLUGINS=1 RAILS\_ENV=test rake db:migrate

---

<div class="post-metadata">

### Author: ![zibetnu](https://avatars.discourse-cdn.com/v4/letter/z/54ee81/32.png) [@zibetnu](https://meta.discourse.org/u/zibetnu)
#### Post date: [February 29, 2024, 10:20pm UTC](https://meta.discourse.org/t/how-to-troubleshoot-database-errors-in-an-outdated-plugin/297339/3 "2024-02-29T22:20:52Z")

</div>

Thanks for the quick reply! I just noticed `d/migrate`, which seemed to fix the issue after I ran it. How does that compare to `LOAD_PLUGINS=1 RAILS_ENV=test rake db:migrate`?

---

<div class="post-metadata">

### Author: ![merefield](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/merefield/32/176214_2.png) [@merefield](https://meta.discourse.org/u/merefield)
#### Post date: [February 29, 2024, 10:55pm UTC](https://meta.discourse.org/t/how-to-troubleshoot-database-errors-in-an-outdated-plugin/297339/4 "2024-02-29T22:55:05Z")

</div>

`d/migrate` is a docker script wrapper.

the command I shared is the real rails command that is run.

alternatively, you can enter the running container and run the rails command.

(but yes, you don’t need to target the test environment!)

---

<div class="post-metadata">

### Author: ![zibetnu](https://avatars.discourse-cdn.com/v4/letter/z/54ee81/32.png) [@zibetnu](https://meta.discourse.org/u/zibetnu)
#### Post date: [February 29, 2024, 11:16pm UTC](https://meta.discourse.org/t/how-to-troubleshoot-database-errors-in-an-outdated-plugin/297339/5 "2024-02-29T23:16:48Z")

</div>

Sounds good! Thanks for the help.

I opened up `d/migrate` and saw that it has everything from the command you shared except `LOAD_PLUGINS=1`. I’m not sure why it worked without that, but that’s all fine by me.

---

<div class="post-metadata">

### Author: ![merefield](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/merefield/32/176214_2.png) [@merefield](https://meta.discourse.org/u/merefield)
#### Post date: [February 29, 2024, 11:21pm UTC](https://meta.discourse.org/t/how-to-troubleshoot-database-errors-in-an-outdated-plugin/297339/6 "2024-02-29T23:21:42Z")

</div>

Good man!

Always good to lift the covers! A lot of people simply don’t read the source code and that is often more helpful than you realise!

Yes that’s an interesting distinction - wonder if its only necessary when doing this for the test environment 🤔

---

<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: [March 30, 2024, 11:22pm UTC](https://meta.discourse.org/t/how-to-troubleshoot-database-errors-in-an-outdated-plugin/297339/7 "2024-03-30T23:22:14Z")

</div>

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