# Restore problem: relation "theme\_fields" does not exist

**URL:** https://meta.discourse.org/t/restore-problem-relation-theme-fields-does-not-exist/95500
**Category:** Self-hosting
**Created:** [August 23, 2018, 6:32pm UTC](https://meta.discourse.org/t/restore-problem-relation-theme-fields-does-not-exist/95500 "2018-08-23T18:32:23Z")
**Posts on this page:** 11
**Page:** 1

<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: [August 23, 2018, 6:32pm UTC](https://meta.discourse.org/t/restore-problem-relation-theme-fields-does-not-exist/95500/1 "2018-08-23T18:32:23Z")

</div>

@tgxworld, I think this is in your wheelhouse.  
Trying to restore a backup from `Discourse 2.1.0.beta5 - https://github.com/discourse/discourse version 8da2d8df3d5f7196f1c267b8a664597a725241ac` or `"Discourse 2.1.0.beta5 - https://github.com/discourse/discourse version bed34b52b51ab903bcb7854cc1efb2bf4107ddfb"` to `f4ae53d52b70a6577a60388f3550f168a4706b5f`

I get

```plaintext
# discourse restore mineral-rights-forum-2018-08-23-033241-v20180812150839.tar.gz
bundler: failed to load command: script/discourse (script/discourse)
ActiveRecord::StatementInvalid: PG::UndefinedTable: ERROR: relation "theme_fields" does not exist
LINE 8: WHERE a.attrelid = '"theme_fields"'::regclass
                                          ^
: SELECT a.attname, format_type(a.atttypid, a.atttypmod),
                     pg_get_expr(d.adbin, d.adrelid), a.attnotnull, a.atttypid, a.atttypmod,
                     c.collname, col_description(a.attrelid, a.attnum) AS comment
                FROM pg_attribute a
                LEFT JOIN pg_attrdef d ON a.attrelid = d.adrelid AND a.attnum = d.adnum
                LEFT JOIN pg_type t ON a.atttypid = t.oid
                LEFT JOIN pg_collation c ON a.attcollation = c.oid AND a.attcollation <> t.typcollation
               WHERE a.attrelid = '"theme_fields"'::regclass
                 AND a.attnum > 0 AND NOT a.attisdropped
               ORDER BY a.attnum

```

I tried restoring a backup from Beta 4 and it fails the same way, so I think it’s a problem with the current Discourse restoring, not the way that backups are created.

EDIT: It looks like the first time that I restore it works, but if I restore again, it fails. I’ve not yet tested this on more than one database.

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [August 30, 2018, 2:37am UTC](https://meta.discourse.org/t/restore-problem-relation-theme-fields-does-not-exist/95500/2 "2018-08-30T02:37:44Z")

</div>

Going to have to ship this into the #Support category, there could be some sort of bug here, but we need a proper repro that works consistently.

Can you consistently make this fail?

---

<div class="post-metadata">

### Author: ![adrelanos](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/adrelanos/32/121409_2.png) [@adrelanos](https://meta.discourse.org/u/adrelanos)
#### Post date: [May 21, 2020, 3:03pm UTC](https://meta.discourse.org/t/restore-problem-relation-theme-fields-does-not-exist/95500/3 "2020-05-21T15:03:02Z")

</div>

Me too got this issue now.

What I did:

I did a backup with discourse `2.5.0.beta4`.

as root

```plaintext
git clone https://github.com/discourse/discourse_docker.git /var/discourse

```

```plaintext
cd /var/discourse

```

```plaintext
cp /var/production-backup/var/discourse/containers/app.yml /var/discourse/containers/

```

```plaintext
mkdir -p /var/discourse/shared/standalone/backups/default/

```

```plaintext
cp /var/production-backup/var/discourse/shared/standalone/backups/default/whonix-forum-2020-05-21-132423-v20200506044956.tar.gz /var/discourse/shared/standalone/backups/default/

```

```plaintext
./launcher enter app

```

```plaintext
discourse enable_restore

```

```plaintext
discourse restore whonix-forum-2020-05-21-132423-v20200506044956.tar.gz

```

result:

```plaintext
root@host-app:/var/www/discourse# discourse restore whonix-forum-2020-05-21-132423-v20200506044956.tar.gz
bundler: failed to load command: script/discourse (script/discourse)
ActiveRecord::StatementInvalid: PG::UndefinedTable: ERROR: relation "theme_fields" does not exist
LINE 8: WHERE a.attrelid = '"theme_fields"'::regclass
                            ^

  /var/www/discourse/vendor/bundle/ruby/2.6.0/gems/rack-mini-profiler-2.0.1/lib/patches/db/pg.rb:110:in `exec'
  /var/www/discourse/vendor/bundle/ruby/2.6.0/gems/rack-mini-profiler-2.0.1/lib/patches/db/pg.rb:110:in `async_exec'
  /var/www/discourse/vendor/bundle/ruby/2.6.0/gems/activerecord-6.0.3/lib/active_record/connection_adapters/postgresql/database_statements.rb:65:in `block (2 levels) in query'
  /var/www/discourse/vendor/bundle/ruby/2.6.0/gems/activesupport-6.0.3/lib/active_support/dependencies/interlock.rb:48:in `block in permit_concurrent_loads'
  /var/www/discourse/vendor/bundle/ruby/2.6.0/gems/activesupport-6.0.3/lib/active_support/concurrency/share_lock.rb:187:in `yield_shares'
  /var/www/discourse/vendor/bundle/ruby/2.6.0/gems/activesupport-6.0.3/lib/active_support/dependencies/interlock.rb:47:in `permit_concurrent_loads'
  /var/www/discourse/vendor/bundle/ruby/2.6.0/gems/activerecord-6.0.3/lib/active_record/connection_adapters/postgresql/database_statements.rb:64:in `block in query'
  /var/www/discourse/vendor/bundle/ruby/2.6.0/gems/activerecord-6.0.3/lib/active_record/connection_adapters/abstract_adapter.rb:722:in `block (2 levels) in log'
  /var/www/discourse/vendor/bundle/ruby/2.6.0/gems/activesupport-6.0.3/lib/active_support/concurrency/load_interlock_aware_monitor.rb:26:in `block (2 levels) in synchronize'
  /var/www/discourse/vendor/bundle/ruby/2.6.0/gems/activesupport-6.0.3/lib/active_support/concurrency/load_interlock_aware_monitor.rb:25:in `handle_interrupt'
  /var/www/discourse/vendor/bundle/ruby/2.6.0/gems/activesupport-6.0.3/lib/active_support/concurrency/load_interlock_aware_monitor.rb:25:in `block in synchronize'
  /var/www/discourse/vendor/bundle/ruby/2.6.0/gems/activesupport-6.0.3/lib/active_support/concurrency/load_interlock_aware_monitor.rb:21:in `handle_interrupt'
  /var/www/discourse/vendor/bundle/ruby/2.6.0/gems/activesupport-6.0.3/lib/active_support/concurrency/load_interlock_aware_monitor.rb:21:in `synchronize'
  /var/www/discourse/vendor/bundle/ruby/2.6.0/gems/activerecord-6.0.3/lib/active_record/connection_adapters/abstract_adapter.rb:721:in `block in log'
  /var/www/discourse/vendor/bundle/ruby/2.6.0/gems/activesupport-6.0.3/lib/active_support/notifications/instrumenter.rb:24:in `instrument'
  /var/www/discourse/vendor/bundle/ruby/2.6.0/gems/activerecord-6.0.3/lib/active_record/connection_adapters/abstract_adapter.rb:712:in `log'
  /var/www/discourse/vendor/bundle/ruby/2.6.0/gems/activerecord-6.0.3/lib/active_record/connection_adapters/postgresql/database_statements.rb:63:in `query'
  /var/www/discourse/vendor/bundle/ruby/2.6.0/gems/activerecord-6.0.3/lib/active_record/connection_adapters/postgresql_adapter.rb:820:in `column_definitions'
  /var/www/discourse/vendor/bundle/ruby/2.6.0/gems/activerecord-6.0.3/lib/active_record/connection_adapters/abstract/schema_statements.rb:114:in `columns'
  /var/www/discourse/vendor/bundle/ruby/2.6.0/gems/activerecord-6.0.3/lib/active_record/connection_adapters/schema_cache.rb:76:in `columns'
  /var/www/discourse/vendor/bundle/ruby/2.6.0/gems/activerecord-6.0.3/lib/active_record/connection_adapters/schema_cache.rb:82:in `columns_hash'
  /var/www/discourse/vendor/bundle/ruby/2.6.0/gems/activerecord-6.0.3/lib/active_record/model_schema.rb:488:in `load_schema!'
  /var/www/discourse/vendor/bundle/ruby/2.6.0/gems/activerecord-6.0.3/lib/active_record/attributes.rb:247:in `load_schema!'
  /var/www/discourse/vendor/bundle/ruby/2.6.0/gems/activerecord-6.0.3/lib/active_record/attribute_decorators.rb:50:in `load_schema!'
  /var/www/discourse/vendor/bundle/ruby/2.6.0/gems/activerecord-6.0.3/lib/active_record/model_schema.rb:478:in `block in load_schema'
  /usr/local/lib/ruby/2.6.0/monitor.rb:235:in `mon_synchronize'
  /var/www/discourse/vendor/bundle/ruby/2.6.0/gems/activerecord-6.0.3/lib/active_record/model_schema.rb:475:in `load_schema'
  /var/www/discourse/vendor/bundle/ruby/2.6.0/gems/activerecord-6.0.3/lib/active_record/model_schema.rb:352:in `columns_hash'
  /var/www/discourse/vendor/bundle/ruby/2.6.0/gems/activerecord-6.0.3/lib/active_record/dynamic_matchers.rb:60:in `block in valid?'
  /var/www/discourse/vendor/bundle/ruby/2.6.0/gems/activerecord-6.0.3/lib/active_record/dynamic_matchers.rb:60:in `all?'
  /var/www/discourse/vendor/bundle/ruby/2.6.0/gems/activerecord-6.0.3/lib/active_record/dynamic_matchers.rb:60:in `valid?'
  /var/www/discourse/vendor/bundle/ruby/2.6.0/gems/activerecord-6.0.3/lib/active_record/dynamic_matchers.rb:11:in `respond_to_missing?'
  /var/www/discourse/vendor/bundle/ruby/2.6.0/gems/activerecord-6.0.3/lib/active_record/scoping/named.rb:209:in `respond_to?'
  /var/www/discourse/vendor/bundle/ruby/2.6.0/gems/activerecord-6.0.3/lib/active_record/scoping/named.rb:209:in `valid_scope_name?'
  /var/www/discourse/vendor/bundle/ruby/2.6.0/gems/activerecord-6.0.3/lib/active_record/scoping/named.rb:187:in `scope'
  /var/www/discourse/app/models/theme_field.rb:8:in `<class:ThemeField>'
  /var/www/discourse/app/models/theme_field.rb:3:in `<top (required)>'
  /var/www/discourse/vendor/bundle/ruby/2.6.0/gems/zeitwerk-2.3.0/lib/zeitwerk/kernel.rb:16:in `require'
  /var/www/discourse/vendor/bundle/ruby/2.6.0/gems/zeitwerk-2.3.0/lib/zeitwerk/kernel.rb:16:in `require'
  /var/www/discourse/vendor/bundle/ruby/2.6.0/gems/zeitwerk-2.3.0/lib/zeitwerk/loader.rb:381:in `const_get'
  /var/www/discourse/vendor/bundle/ruby/2.6.0/gems/zeitwerk-2.3.0/lib/zeitwerk/loader.rb:381:in `block (2 levels) in eager_load'
  /var/www/discourse/vendor/bundle/ruby/2.6.0/gems/zeitwerk-2.3.0/lib/zeitwerk/loader.rb:723:in `block in ls'
  /var/www/discourse/vendor/bundle/ruby/2.6.0/gems/zeitwerk-2.3.0/lib/zeitwerk/loader.rb:720:in `foreach'
  /var/www/discourse/vendor/bundle/ruby/2.6.0/gems/zeitwerk-2.3.0/lib/zeitwerk/loader.rb:720:in `ls'
  /var/www/discourse/vendor/bundle/ruby/2.6.0/gems/zeitwerk-2.3.0/lib/zeitwerk/loader.rb:376:in `block in eager_load'
  /var/www/discourse/vendor/bundle/ruby/2.6.0/gems/zeitwerk-2.3.0/lib/zeitwerk/loader.rb:368:in `synchronize'
  /var/www/discourse/vendor/bundle/ruby/2.6.0/gems/zeitwerk-2.3.0/lib/zeitwerk/loader.rb:368:in `eager_load'
  /var/www/discourse/vendor/bundle/ruby/2.6.0/gems/zeitwerk-2.3.0/lib/zeitwerk/loader.rb:483:in `each'
  /var/www/discourse/vendor/bundle/ruby/2.6.0/gems/zeitwerk-2.3.0/lib/zeitwerk/loader.rb:483:in `eager_load_all'
  /var/www/discourse/vendor/bundle/ruby/2.6.0/gems/railties-6.0.3/lib/rails/application/finisher.rb:122:in `block in <module:Finisher>'
  /var/www/discourse/vendor/bundle/ruby/2.6.0/gems/railties-6.0.3/lib/rails/initializable.rb:32:in `instance_exec'
  /var/www/discourse/vendor/bundle/ruby/2.6.0/gems/railties-6.0.3/lib/rails/initializable.rb:32:in `run'
  /var/www/discourse/vendor/bundle/ruby/2.6.0/gems/railties-6.0.3/lib/rails/initializable.rb:61:in `block in run_initializers'
  /usr/local/lib/ruby/2.6.0/tsort.rb:228:in `block in tsort_each'
  /usr/local/lib/ruby/2.6.0/tsort.rb:350:in `block (2 levels) in each_strongly_connected_component'
  /usr/local/lib/ruby/2.6.0/tsort.rb:431:in `each_strongly_connected_component_from'
  /usr/local/lib/ruby/2.6.0/tsort.rb:349:in `block in each_strongly_connected_component'
  /usr/local/lib/ruby/2.6.0/tsort.rb:347:in `each'
  /usr/local/lib/ruby/2.6.0/tsort.rb:347:in `call'
  /usr/local/lib/ruby/2.6.0/tsort.rb:347:in `each_strongly_connected_component'
  /usr/local/lib/ruby/2.6.0/tsort.rb:226:in `tsort_each'
  /usr/local/lib/ruby/2.6.0/tsort.rb:205:in `tsort_each'
  /var/www/discourse/vendor/bundle/ruby/2.6.0/gems/railties-6.0.3/lib/rails/initializable.rb:60:in `run_initializers'
  /var/www/discourse/vendor/bundle/ruby/2.6.0/gems/railties-6.0.3/lib/rails/application.rb:363:in `initialize!'
  /var/www/discourse/vendor/bundle/ruby/2.6.0/gems/railties-6.0.3/lib/rails/railtie.rb:190:in `public_send'
  /var/www/discourse/vendor/bundle/ruby/2.6.0/gems/railties-6.0.3/lib/rails/railtie.rb:190:in `method_missing'
  /var/www/discourse/config/environment.rb:7:in `<top (required)>'
  script/discourse:264:in `require'
  script/discourse:264:in `load_rails'
  script/discourse:119:in `restore'
  /var/www/discourse/vendor/bundle/ruby/2.6.0/gems/thor-1.0.1/lib/thor/command.rb:27:in `run'
  /var/www/discourse/vendor/bundle/ruby/2.6.0/gems/thor-1.0.1/lib/thor/invocation.rb:127:in `invoke_command'
  /var/www/discourse/vendor/bundle/ruby/2.6.0/gems/thor-1.0.1/lib/thor.rb:392:in `dispatch'
  /var/www/discourse/vendor/bundle/ruby/2.6.0/gems/thor-1.0.1/lib/thor/base.rb:485:in `start'
  script/discourse:284:in `<top (required)>'
root@host-app:/var/www/discourse#

```

> [@sam](#):
>
> Can you consistently make this fail?

Happened twice. Dunno how to proceed from here.

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [May 22, 2020, 12:43am UTC](https://meta.discourse.org/t/restore-problem-relation-theme-fields-does-not-exist/95500/4 "2020-05-22T00:43:19Z")

</div>

Can you restore it via the UI ?

---

<div class="post-metadata">

### Author: ![adrelanos](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/adrelanos/32/121409_2.png) [@adrelanos](https://meta.discourse.org/u/adrelanos)
#### Post date: [May 22, 2020, 3:00pm UTC](https://meta.discourse.org/t/restore-problem-relation-theme-fields-does-not-exist/95500/5 "2020-05-22T15:00:15Z")

</div>

No.

```plaintext
> [2020-05-22 12:11:36] 'Patrick' has started the restore!
> [2020-05-22 12:11:36] Marking restore as running...
> [2020-05-22 12:11:36] Making sure /var/www/discourse/tmp/restores/default/2020-05-22-121136 exists...
> [2020-05-22 12:11:36] Copying archive to tmp directory...
> [2020-05-22 12:11:40] Unzipping archive, this may take a while...
> [2020-05-22 12:11:47] Extracting dump file...
> [2020-05-22 12:11:58] Validating metadata...
> [2020-05-22 12:11:58] Current version: 20200522004855
> [2020-05-22 12:11:58] Restored version: 20200506044956
> [2020-05-22 12:11:58] Enabling readonly mode...
> [2020-05-22 12:11:58] Pausing sidekiq...
> [2020-05-22 12:11:58] Waiting up to 60 seconds for Sidekiq to finish running jobs...
> [2020-05-22 12:12:06] Creating missing functions in the discourse_functions schema...

```

Then even hours later, nothing happening.

Reload page.

> Oops
> 
> The software powering this discussion forum encountered an unexpected problem. We apologize for the inconvenience.
> 
> Detailed information about the error was logged, and an automatic notification generated. We’ll take a look at it.
> 
> No further action is necessary. However, if the error condition persists, you can provide additional detail, including steps to reproduce the error, by posting a discussion topic in the site’s feedback category.

```
root@whonix:/var/discourse# ./launcher logs app

```

```plaintext
> run-parts: executing /etc/runit/1.d/00-ensure-links
> run-parts: executing /etc/runit/1.d/00-fix-var-logs
> run-parts: executing /etc/runit/1.d/anacron
> run-parts: executing /etc/runit/1.d/cleanup-pids
> Cleaning stale PID files
> run-parts: executing /etc/runit/1.d/copy-env
> Started runsvdir, PID is 38
> ok: run: redis: (pid 52) 0s
> ok: run: postgres: (pid 51) 0s
> chgrp: invalid group: ‘syslog’
> rsyslogd: imklog: cannot open kernel log (/proc/kmsg): Operation not permitted.
> rsyslogd: activation of module imklog failed [v8.1901.0 try https://www.rsyslog.com/e/2145]
> supervisor pid: 47 unicorn pid: 77
> root@whonix:/var/discourse# 

```

```
`root@whonix:/var/discourse# ./launcher enter app`

```

Possible.

`root@whonix-app:/var/www/discourse#`

```plaintext
tail shared/standalone/log/rails/production.log

```

```plaintext
Unexpected error in Message Bus : PG::UndefinedTable: ERROR: relation "user_auth_tokens" does not exist
LINE 1: SELECT "user_auth_tokens".* FROM "user_auth_tokens" WHERE ((...
                                         ^

Job exception: PG::UndefinedTable: ERROR: relation "application_requests" does not exist
LINE 1: SELECT "application_requests"."id" FROM "application_request...

```

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [May 25, 2020, 3:06am UTC](https://meta.discourse.org/t/restore-problem-relation-theme-fields-does-not-exist/95500/6 "2020-05-25T03:06:59Z")

</div>

Something is not right about your backup.

Can you extract it on local and load it into a PG database? The gzip contains 2 files … 1 backups of PG and 1 uploads directory.

---

<div class="post-metadata">

### Author: ![adrelanos](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/adrelanos/32/121409_2.png) [@adrelanos](https://meta.discourse.org/u/adrelanos)
#### Post date: [May 25, 2020, 1:43pm UTC](https://meta.discourse.org/t/restore-problem-relation-theme-fields-does-not-exist/95500/7 "2020-05-25T13:43:17Z")

</div>

Thank you for help!

I’ve created a new backup from the still fully functional old production server.

Purged both docker and discourse from newer stage server. Re-installed both docker and discourse according official instructions. Then went with command line restoration instructions.

The backup was created with `docker-engine 17.05.0~ce-0~debian-stretch` and to be restored with `docker-ce-cli 5:19.03.9~3-0~debian-buster`. This also results in a newer postgres version. (old: 10; new: 12)

Is it a legitimate approach to backup an outdated docker/postgres version and try to restore on an up to date docker/discourse installation?

Getting a different error this time.

```
ERROR: could not create unique index "index_incoming_referers_on_path_and_incoming_domain_id"
DETAIL: Key (path, incoming_domain_id)=(/wiki/Tor_Browser, 3) is duplicated.
EXCEPTION: psql failed: DETAIL: Key (path, incoming_domain_id)=(/wiki/Tor_Browser, 3) is duplicated.

```

Full log:

```plaintext
root@whonix-app:/var/www/discourse# discourse restore whonix-forum-2020-05-25-065253-v20200506044956.tar.gz
Starting restore: whonix-forum-2020-05-25-065253-v20200506044956.tar.gz
[STARTED]
'system' has started the restore!
Marking restore as running...
Making sure /var/www/discourse/tmp/restores/default/2020-05-25-132224 exists...
Copying archive to tmp directory...
Unzipping archive, this may take a while...
Extracting dump file...
Validating metadata...
  Current version: 20200524181959
  Restored version: 20200506044956
Enabling readonly mode...
Pausing sidekiq...
Waiting up to 60 seconds for Sidekiq to finish running jobs...
Creating missing functions in the discourse_functions schema...
Restoring dump file... (this may take a while)
[cut]
ALTER TABLE
[cut lots of duplicate ALTER TABLE lines]
ALTER TABLE
CREATE INDEX
[cut lots of duplicate CREATE INDEX lines]
CREATE INDEX
ERROR: could not create unique index "index_incoming_referers_on_path_and_incoming_domain_id"
DETAIL: Key (path, incoming_domain_id)=(/wiki/Tor_Browser, 3) is duplicated.
EXCEPTION: psql failed: DETAIL: Key (path, incoming_domain_id)=(/wiki/Tor_Browser, 3) is duplicated.
/var/www/discourse/lib/backup_restore/database_restorer.rb:95:in `restore_dump'
/var/www/discourse/lib/backup_restore/database_restorer.rb:26:in `restore'
/var/www/discourse/lib/backup_restore/restorer.rb:49:in `run'
script/discourse:143:in `restore'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/thor-1.0.1/lib/thor/command.rb:27:in `run'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/thor-1.0.1/lib/thor/invocation.rb:127:in `invoke_command'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/thor-1.0.1/lib/thor.rb:392:in `dispatch'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/thor-1.0.1/lib/thor/base.rb:485:in `start'
script/discourse:284:in `<top (required)>'
/usr/local/lib/ruby/gems/2.6.0/gems/bundler-2.1.4/lib/bundler/cli/exec.rb:63:in `load'
/usr/local/lib/ruby/gems/2.6.0/gems/bundler-2.1.4/lib/bundler/cli/exec.rb:63:in `kernel_load'
/usr/local/lib/ruby/gems/2.6.0/gems/bundler-2.1.4/lib/bundler/cli/exec.rb:28:in `run'
/usr/local/lib/ruby/gems/2.6.0/gems/bundler-2.1.4/lib/bundler/cli.rb:476:in `exec'
/usr/local/lib/ruby/gems/2.6.0/gems/bundler-2.1.4/lib/bundler/vendor/thor/lib/thor/command.rb:27:in `run'
/usr/local/lib/ruby/gems/2.6.0/gems/bundler-2.1.4/lib/bundler/vendor/thor/lib/thor/invocation.rb:127:in `invoke_command'
/usr/local/lib/ruby/gems/2.6.0/gems/bundler-2.1.4/lib/bundler/vendor/thor/lib/thor.rb:399:in `dispatch'
/usr/local/lib/ruby/gems/2.6.0/gems/bundler-2.1.4/lib/bundler/cli.rb:30:in `dispatch'
/usr/local/lib/ruby/gems/2.6.0/gems/bundler-2.1.4/lib/bundler/vendor/thor/lib/thor/base.rb:476:in `start'
/usr/local/lib/ruby/gems/2.6.0/gems/bundler-2.1.4/lib/bundler/cli.rb:24:in `start'
/usr/local/lib/ruby/gems/2.6.0/gems/bundler-2.1.4/exe/bundle:46:in `block in <top (required)>'
/usr/local/lib/ruby/gems/2.6.0/gems/bundler-2.1.4/lib/bundler/friendly_errors.rb:123:in `with_friendly_errors'
/usr/local/lib/ruby/gems/2.6.0/gems/bundler-2.1.4/exe/bundle:34:in `<top (required)>'
/usr/local/bin/bundle:23:in `load'
/usr/local/bin/bundle:23:in `<main>'
Trying to rollback...
Rolling back...
Cleaning stuff up...
Dropping functions from the discourse_functions schema...
Removing tmp '/var/www/discourse/tmp/restores/default/2020-05-25-132224' directory...
Unpausing sidekiq...
Disabling readonly mode...
Marking restore as finished...
Notifying 'system' of the end of the restore...
Finished!
[FAILED]
Restore done.
root@whonix-app:/var/www/discourse#

```

> [@sam](#):
>
> Something is not right about your backup.

I wonder how’s that possible since my old production discourse server is still fully functional. And it’s the second backup I try.

> [@sam](#):
>
> Can you extract it on local and load it into a PG database?

Postgres 10 or postgres 12?

* * *

EDIT:

```plaintext
root@whonix-app:/var/www/discourse# rails c
[1] pry(main)> IncomingReferer.where(path: "/wiki/Tor_Browser")
=> [#<IncomingReferer:0x0000561cba422f48
  id: 11361,
  path: "/wiki/Tor_Browser",
  incoming_domain_id: 3>]
[2] pry(main)> 

```

* * *

EDIT2:

```plaintext
[6] pry(main)> IncomingReferer.where("path LIKE '%/wiki/Tor_Browser%'")
=> [#<IncomingReferer:0x0000561cc08882a8
  id: 19,
  path: "/wiki/Tor_Browser",
  incoming_domain_id: 3>,
 #<IncomingReferer:0x0000561cc08b3f48
  id: 67,
  path: "/wiki/Tor_Browser/Download_Confirmation_Screen",
  incoming_domain_id: 3>,
 #<IncomingReferer:0x0000561cc08b3e08
  id: 331,
  path: "/wiki/Tor_Browser/Internal_Updater",
  incoming_domain_id: 3>,
 #<IncomingReferer:0x0000561cc08b3cf0
  id: 489,
  path: "/wiki/Tor_Browser",

<page break> --- Press enter to continue ( q<enter> to break ) --- <page break>

  incoming_domain_id: 113>,
 #<IncomingReferer:0x0000561cc08b3bb0
  id: 2957,
  path: "/wiki/Tor_Browser/Advanced_Users",
  incoming_domain_id: 617>,
 #<IncomingReferer:0x0000561cc08b3a70
  id: 4052,
  path: "/wiki/Tor_Browser",
  incoming_domain_id: 617>,
 #<IncomingReferer:0x0000561cc08b38e0
  id: 4196,
  path: "/wiki/Tor_Browser",
  incoming_domain_id: 1513>,
 #<IncomingReferer:0x0000561cc08b37f0
  id: 4220,

<page break> --- Press enter to continue ( q<enter> to break ) --- <page break>

  path: "/wiki/Tor_Browser/Advanced_Users",
  incoming_domain_id: 1513>,
 #<IncomingReferer:0x0000561cc08b3700
  id: 4307,
  path: "/wiki/Tor_Browser",
  incoming_domain_id: 1552>,
 #<IncomingReferer:0x0000561cc08b34a8
  id: 4346,
  path: "/wiki/Tor_Browser/Advanced_Users",
  incoming_domain_id: 1552>,
 #<IncomingReferer:0x0000561cc08b3318
  id: 8713,
  path: "/wiki/Tor_Browser/Advanced_Users",
  incoming_domain_id: 3>,
 #<IncomingReferer:0x0000561cc08b3188

<page break> --- Press enter to continue ( q<enter> to break ) --- <page break>

  id: 9746,
  path: "/wiki/Tor_Browser_without_Tor",
  incoming_domain_id: 3>,
 #<IncomingReferer:0x0000561cc08b2f08
  id: 10248,
  path: "/wiki/Tor_Browser_without_Tor",
  incoming_domain_id: 113>,
 #<IncomingReferer:0x0000561cc08b2cb0
  id: 11361,
  path: "/wiki/Tor_Browser",
  incoming_domain_id: 3>,
 #<IncomingReferer:0x0000561cc08b2bc0
  id: 11754,
  path: "/wiki/Tor_Browser/Advanced_Users",
  incoming_domain_id: 113>,

<page break> --- Press enter to continue ( q<enter> to break ) --- <page break>

 #<IncomingReferer:0x0000561cc08b2ad0
  id: 12094,
  path: "/wiki/Tor_Browser/Advanced_Users",
  incoming_domain_id: 4560>,
 #<IncomingReferer:0x0000561cc08b28f0
  id: 12892,
  path: "/wiki/Tor_Browser",
  incoming_domain_id: 4559>,
 #<IncomingReferer:0x0000561cc08b25f8
  id: 13038,
  path: "/wiki/Tor_Browser",
  incoming_domain_id: 4560>]
[7] pry(main)> 
[8] pry(main)>

```

---

<div class="post-metadata">

### Author: ![riking](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/riking/32/170938_2.png) [@riking](https://meta.discourse.org/u/riking)
#### Post date: [May 25, 2020, 5:08pm UTC](https://meta.discourse.org/t/restore-problem-relation-theme-fields-does-not-exist/95500/8 "2020-05-25T17:08:00Z")

</div>

> [@adrelanos](#):
>
> Is it a legitimate approach to backup an outdated docker/postgres version and try to restore on an up to date docker/discourse installation?

Yes, this is supported.

> [@adrelanos](#):
>
> `ERROR: could not create unique index "index_incoming_referers_on_path_and_incoming_domain_id"`

→ [Corrupt indexes in PG12, how do I fix?](https://meta.discourse.org/t/corrupt-indexes-in-pg12-how-do-i-fix/152570)

---

<div class="post-metadata">

### Author: ![Crell](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/crell/32/182999_2.png) [@Crell](https://meta.discourse.org/u/Crell)
#### Post date: [June 4, 2020, 5:18pm UTC](https://meta.discourse.org/t/restore-problem-relation-theme-fields-does-not-exist/95500/9 "2020-06-04T17:18:27Z")

</div>

I am getting the same error as the OP regarding “theme\_fields” even on a brand new Discourse installation.

```plaintext
E, [2020-06-04T16:32:44.492756 #2024] ERROR -- : PG::UndefinedTable: ERROR: relation "theme_fields" does not exist
LINE 8: WHERE a.attrelid = '"theme_fields"'::regclass
                            ^
 (ActiveRecord::StatementInvalid)
/app/.global/gems/rack-mini-profiler-2.0.2/lib/patches/db/pg.rb:110:in `exec'
/app/.global/gems/rack-mini-profiler-2.0.2/lib/patches/db/pg.rb:110:in `async_exec'
/app/.global/gems/activerecord-6.0.1/lib/active_record/connection_adapters/postgresql/database_statements.rb:65:in `block (2 levels) in query'
/app/.global/gems/activesupport-6.0.1/lib/active_support/dependencies/interlock.rb:48:in `block in permit_concurrent_loads'
/app/.global/gems/activesupport-6.0.1/lib/active_support/concurrency/share_lock.rb:187:in `yield_shares'
/app/.global/gems/activesupport-6.0.1/lib/active_support/dependencies/interlock.rb:47:in `permit_concurrent_loads'
/app/.global/gems/activerecord-6.0.1/lib/active_record/connection_adapters/postgresql/database_statements.rb:64:in `block in query'
/app/.global/gems/activerecord-6.0.1/lib/active_record/connection_adapters/abstract_adapter.rb:718:in `block (2 levels) in log'
/opt/ruby/2.6/lib/ruby/2.6.0/monitor.rb:235:in `mon_synchronize'
/app/.global/gems/activerecord-6.0.1/lib/active_record/connection_adapters/abstract_adapter.rb:717:in `block in log'
/app/.global/gems/activesupport-6.0.1/lib/active_support/notifications/instrumenter.rb:24:in `instrument'
/app/.global/gems/activerecord-6.0.1/lib/active_record/connection_adapters/abstract_adapter.rb:708:in `log'
/app/.global/gems/activerecord-6.0.1/lib/active_record/connection_adapters/postgresql/database_statements.rb:63:in `query'
/app/.global/gems/activerecord-6.0.1/lib/active_record/connection_adapters/postgresql_adapter.rb:817:in `column_definitions'
/app/.global/gems/activerecord-6.0.1/lib/active_record/connection_adapters/abstract/schema_statements.rb:114:in `columns'
/app/.global/gems/activerecord-6.0.1/lib/active_record/connection_adapters/schema_cache.rb:76:in `columns'
/app/.global/gems/activerecord-6.0.1/lib/active_record/connection_adapters/schema_cache.rb:82:in `columns_hash'
/app/.global/gems/activerecord-6.0.1/lib/active_record/model_schema.rb:490:in `load_schema!'
/app/.global/gems/activerecord-6.0.1/lib/active_record/attributes.rb:247:in `load_schema!'
/app/.global/gems/activerecord-6.0.1/lib/active_record/attribute_decorators.rb:51:in `load_schema!'
/app/.global/gems/activerecord-6.0.1/lib/active_record/model_schema.rb:480:in `block in load_schema'
/opt/ruby/2.6/lib/ruby/2.6.0/monitor.rb:235:in `mon_synchronize'
/app/.global/gems/activerecord-6.0.1/lib/active_record/model_schema.rb:477:in `load_schema'
/app/.global/gems/activerecord-6.0.1/lib/active_record/model_schema.rb:352:in `columns_hash'
/app/.global/gems/activerecord-6.0.1/lib/active_record/dynamic_matchers.rb:60:in `block in valid?'
/app/.global/gems/activerecord-6.0.1/lib/active_record/dynamic_matchers.rb:60:in `all?'
/app/.global/gems/activerecord-6.0.1/lib/active_record/dynamic_matchers.rb:60:in `valid?'
/app/.global/gems/activerecord-6.0.1/lib/active_record/dynamic_matchers.rb:11:in `respond_to_missing?'
/app/.global/gems/activerecord-6.0.1/lib/active_record/scoping/named.rb:209:in `respond_to?'
/app/.global/gems/activerecord-6.0.1/lib/active_record/scoping/named.rb:209:in `valid_scope_name?'
/app/.global/gems/activerecord-6.0.1/lib/active_record/scoping/named.rb:186:in `scope'
/app/app/models/theme_field.rb:8:in `<class:ThemeField>'
/app/app/models/theme_field.rb:3:in `<top (required)>'
/app/.global/gems/zeitwerk-2.3.0/lib/zeitwerk/kernel.rb:16:in `require'
/app/.global/gems/zeitwerk-2.3.0/lib/zeitwerk/kernel.rb:16:in `require'
/app/.global/gems/zeitwerk-2.3.0/lib/zeitwerk/loader.rb:381:in `const_get'
/app/.global/gems/zeitwerk-2.3.0/lib/zeitwerk/loader.rb:381:in `block (2 levels) in eager_load'
/app/.global/gems/zeitwerk-2.3.0/lib/zeitwerk/loader.rb:723:in `block in ls'
/app/.global/gems/zeitwerk-2.3.0/lib/zeitwerk/loader.rb:720:in `foreach'
/app/.global/gems/zeitwerk-2.3.0/lib/zeitwerk/loader.rb:720:in `ls'
/app/.global/gems/zeitwerk-2.3.0/lib/zeitwerk/loader.rb:376:in `block in eager_load'
/app/.global/gems/zeitwerk-2.3.0/lib/zeitwerk/loader.rb:368:in `synchronize'
/app/.global/gems/zeitwerk-2.3.0/lib/zeitwerk/loader.rb:368:in `eager_load'
/app/.global/gems/zeitwerk-2.3.0/lib/zeitwerk/loader.rb:483:in `each'
/app/.global/gems/zeitwerk-2.3.0/lib/zeitwerk/loader.rb:483:in `eager_load_all'
/app/.global/gems/railties-6.0.1/lib/rails/application/finisher.rb:122:in `block in <module:Finisher>'
/app/.global/gems/railties-6.0.1/lib/rails/initializable.rb:32:in `instance_exec'
/app/.global/gems/railties-6.0.1/lib/rails/initializable.rb:32:in `run'
/app/.global/gems/railties-6.0.1/lib/rails/initializable.rb:61:in `block in run_initializers'
/opt/ruby/2.6/lib/ruby/2.6.0/tsort.rb:228:in `block in tsort_each'
/opt/ruby/2.6/lib/ruby/2.6.0/tsort.rb:350:in `block (2 levels) in each_strongly_connected_component'
/opt/ruby/2.6/lib/ruby/2.6.0/tsort.rb:431:in `each_strongly_connected_component_from'
/opt/ruby/2.6/lib/ruby/2.6.0/tsort.rb:349:in `block in each_strongly_connected_component'
/opt/ruby/2.6/lib/ruby/2.6.0/tsort.rb:347:in `each'
/opt/ruby/2.6/lib/ruby/2.6.0/tsort.rb:347:in `call'
/opt/ruby/2.6/lib/ruby/2.6.0/tsort.rb:347:in `each_strongly_connected_component'
/opt/ruby/2.6/lib/ruby/2.6.0/tsort.rb:226:in `tsort_each'
/opt/ruby/2.6/lib/ruby/2.6.0/tsort.rb:205:in `tsort_each'
/app/.global/gems/railties-6.0.1/lib/rails/initializable.rb:60:in `run_initializers'
/app/.global/gems/railties-6.0.1/lib/rails/application.rb:363:in `initialize!'
/app/.global/gems/railties-6.0.1/lib/rails/railtie.rb:190:in `public_send'
/app/.global/gems/railties-6.0.1/lib/rails/railtie.rb:190:in `method_missing'
/app/config/environment.rb:7:in `<top (required)>'

```

I get that repeated numerous times in my application log. I’m not clear what is triggering it. I’m on PostgreSQL 9.6, if that matters.

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [June 5, 2020, 6:57am UTC](https://meta.discourse.org/t/restore-problem-relation-theme-fields-does-not-exist/95500/10 "2020-06-05T06:57:22Z")

</div>

Are you running the latest version of Discourse? Is this an upgrade from an ancient version of Discourse?

---

<div class="post-metadata">

### Author: ![Crell](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/crell/32/182999_2.png) [@Crell](https://meta.discourse.org/u/Crell)
#### Post date: [June 5, 2020, 2:38pm UTC](https://meta.discourse.org/t/restore-problem-relation-theme-fields-does-not-exist/95500/11 "2020-06-05T14:38:57Z")

</div>

This is a brand new fresh install of Discourse 2.4, no previous anything.

I also tried upgrading to Postgres 12. Error still appears in my logs.
