# PG Error on rebuild - column "token" of relation "email\_tokens" does not exist

**URL:** https://meta.discourse.org/t/pg-error-on-rebuild-column-token-of-relation-email-tokens-does-not-exist/211934
**Category:** Self-hosting
**Created:** [December 13, 2021, 9:03am UTC](https://meta.discourse.org/t/pg-error-on-rebuild-column-token-of-relation-email-tokens-does-not-exist/211934 "2021-12-13T09:03:41Z")
**Posts on this page:** 14
**Page:** 1

<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: [December 13, 2021, 9:03am UTC](https://meta.discourse.org/t/pg-error-on-rebuild-column-token-of-relation-email-tokens-does-not-exist/211934/1 "2021-12-13T09:03:41Z")

</div>

Getting:

```plaintext
2021-12-13 08:57:12.809 UTC [902] discourse@discourse ERROR: column "token" of relation "email_tokens" does not exist
2021-12-13 08:57:12.809 UTC [902] discourse@discourse STATEMENT: ALTER TABLE email_tokens ALTER COLUMN token DROP NOT NULL

rake aborted!
StandardError: An error has occurred, this and all later migrations canceled:

PG::UndefinedColumn: ERROR: column "token" of relation "email_tokens" does not exist

```

Related to?:

[https://github.com/discourse/discourse/commit/5fc42bf76927effb1f8816bf7418782e22ccd9a5](https://github.com/discourse/discourse/commit/5fc42bf76927effb1f8816bf7418782e22ccd9a5)

---

<div class="post-metadata">

### Author: ![alexsts](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/alexsts/32/219847_2.png) [@alexsts](https://meta.discourse.org/u/alexsts)
#### Post date: [December 13, 2021, 10:02am UTC](https://meta.discourse.org/t/pg-error-on-rebuild-column-token-of-relation-email-tokens-does-not-exist/211934/2 "2021-12-13T10:02:31Z")

</div>

We also have this issue.

For now, we were successful in starting the old container with `./launcher start app` after the failed rebuild, but we don’t know whether our database is in a consistent state since the failure occurred part-way through migration.

For our peace of mind, is it known whether the database migration is fully rolled back when a failure like this occurs?

---

<div class="post-metadata">

### Author: ![AquaL1te](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/aqual1te/32/201966_2.png) [@AquaL1te](https://meta.discourse.org/u/AquaL1te)
#### Post date: [December 13, 2021, 10:26am UTC](https://meta.discourse.org/t/pg-error-on-rebuild-column-token-of-relation-email-tokens-does-not-exist/211934/3 "2021-12-13T10:26:58Z")

</div>

Same here, rolling back a backup from 8 hours ago.

---

<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: [December 13, 2021, 10:43am UTC](https://meta.discourse.org/t/pg-error-on-rebuild-column-token-of-relation-email-tokens-does-not-exist/211934/4 "2021-12-13T10:43:55Z")

</div>

Sounds like a bug. I don’t suppose that you have SKIP\_POST\_DEPLOYMENT\_MIGRATIONS set, so you?

Or, maybe as a work around you can set it to 1 in your `app.yml`, run the rebuild, and then either change it back and upgrade again or inside the container, set it to zero and migrate on the command line.

---

<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: [December 13, 2021, 11:32am UTC](https://meta.discourse.org/t/pg-error-on-rebuild-column-token-of-relation-email-tokens-does-not-exist/211934/5 "2021-12-13T11:32:21Z")

</div>

> [@pfaffman](#):
>
> I don’t suppose that you have SKIP\_POST\_DEPLOYMENT\_MIGRATIONS set, so you?

Thanks for the suggestion Jay, but no, I don’t appear to have this set in `app.yml`.

---

<div class="post-metadata">

### Author: ![david](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/david/32/157490_2.png) [@david](https://meta.discourse.org/u/david)
#### Post date: [December 13, 2021, 4:08pm UTC](https://meta.discourse.org/t/pg-error-on-rebuild-column-token-of-relation-email-tokens-does-not-exist/211934/6 "2021-12-13T16:08:10Z")

</div>

Please can someone with this issue try running this on the rails console, and share your result:

```bash
./launcher enter app
rails c

```

…

```ruby
DB.query "SELECT table_schema, table_name, column_name FROM INFORMATION_SCHEMA.COLUMNS WHERE table_name='email_tokens' AND column_name='token';"

```

---

<div class="post-metadata">

### Author: ![aksoforever](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/aksoforever/32/502615_2.png) [@aksoforever](https://meta.discourse.org/u/aksoforever)
#### Post date: [December 13, 2021, 4:12pm UTC](https://meta.discourse.org/t/pg-error-on-rebuild-column-token-of-relation-email-tokens-does-not-exist/211934/8 "2021-12-13T16:12:27Z")

</div>

![image](https://global.discourse-cdn.com/meta/original/3X/d/5/d5e31409a57f12a45fe43096cd5ca24a46b944ac.png)

can you please have a look  
seems every rebuild have this error

---

<div class="post-metadata">

### Author: ![david](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/david/32/157490_2.png) [@david](https://meta.discourse.org/u/david)
#### Post date: [December 13, 2021, 4:15pm UTC](https://meta.discourse.org/t/pg-error-on-rebuild-column-token-of-relation-email-tokens-does-not-exist/211934/9 "2021-12-13T16:15:08Z")

</div>

Perfect, thanks @aksoforever - that confirms my suspicion. I think this PR should take care of it:

[https://github.com/discourse/discourse/pull/15277](https://github.com/discourse/discourse/pull/15277)

---

<div class="post-metadata">

### Author: ![aksoforever](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/aksoforever/32/502615_2.png) [@aksoforever](https://meta.discourse.org/u/aksoforever)
#### Post date: [December 13, 2021, 4:20pm UTC](https://meta.discourse.org/t/pg-error-on-rebuild-column-token-of-relation-email-tokens-does-not-exist/211934/10 "2021-12-13T16:20:36Z")

</div>

after rebuild still have the error

 ![image](https://global.discourse-cdn.com/meta/original/3X/1/9/19afcb0d35ab2fd3426535530a416df9cfcefda3.png)

seems, i need rebuild again, let me try it.

---

<div class="post-metadata">

### Author: ![david](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/david/32/157490_2.png) [@david](https://meta.discourse.org/u/david)
#### Post date: [December 13, 2021, 4:21pm UTC](https://meta.discourse.org/t/pg-error-on-rebuild-column-token-of-relation-email-tokens-does-not-exist/211934/11 "2021-12-13T16:21:41Z")

</div>

It’ll take 10-15mins for that commit to reach the `tests-passed` branch. I’ll post here when it’s done.

---

<div class="post-metadata">

### Author: ![david](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/david/32/157490_2.png) [@david](https://meta.discourse.org/u/david)
#### Post date: [December 13, 2021, 4:34pm UTC](https://meta.discourse.org/t/pg-error-on-rebuild-column-token-of-relation-email-tokens-does-not-exist/211934/12 "2021-12-13T16:34:59Z")

</div>

Ok, that commit is now live in tests-passed

cc @aksoforever @merefield @alexsts @AquaL1te @pfaffman @TechGeek - a rebuild should work now. Sorry for the disruption!

---

<div class="post-metadata">

### Author: ![aksoforever](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/aksoforever/32/502615_2.png) [@aksoforever](https://meta.discourse.org/u/aksoforever)
#### Post date: [December 13, 2021, 4:46pm UTC](https://meta.discourse.org/t/pg-error-on-rebuild-column-token-of-relation-email-tokens-does-not-exist/211934/13 "2021-12-13T16:46:58Z")

</div>

Yes, works perfect. thanks David.  
very very helpful.

---

<div class="post-metadata">

### Author: ![david](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/david/32/157490_2.png) [@david](https://meta.discourse.org/u/david)
#### Post date: [December 14, 2021, 8:00am UTC](https://meta.discourse.org/t/pg-error-on-rebuild-column-token-of-relation-email-tokens-does-not-exist/211934/14 "2021-12-14T08:00:29Z")

</div>

This topic was automatically closed after 15 hours. New replies are no longer allowed.

---

<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: [December 15, 2021, 7:39pm UTC](https://meta.discourse.org/t/pg-error-on-rebuild-column-token-of-relation-email-tokens-does-not-exist/211934/15 "2021-12-15T19:39:56Z")

</div>

Oh, great catch ! Thanks David
