# DuplicateColumn and multisite:migrate failed

**URL:** https://meta.discourse.org/t/duplicatecolumn-and-multisite-migrate-failed/224480
**Category:** Bug
**Created:** [April 16, 2022, 9:57am UTC](https://meta.discourse.org/t/duplicatecolumn-and-multisite-migrate-failed/224480 "2022-04-16T09:57:08Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![jupiter](https://avatars.discourse-cdn.com/v4/letter/j/53a042/32.png) [@jupiter](https://meta.discourse.org/u/jupiter)
#### Post date: [April 16, 2022, 9:57am UTC](https://meta.discourse.org/t/duplicatecolumn-and-multisite-migrate-failed/224480/1 "2022-04-16T09:57:08Z")

</div>

Upgrading from 2.9.0.beta2 to 2.9.0.beta4 failed with error message `PG::DuplicateColumn: ERROR: column "bookmarkable_id" of relation "bookmarks" already exists`. The advice in [Recovering from failed/partially applied upgrade](https://meta.discourse.org/t/recovering-from-failed-partially-applied-upgrade/221924) helped me to get back online again. I’m starting a new topic because this issue seems to be specifically about a (dockerized) multisite install.

The issue seems to be `multisite:migrate` trying to run again the same migration that was already ran as part of the earlier migrations. The result was `PG::DuplicateColumn: ERROR: column "bookmarkable_id" of relation "bookmarks" already exists`. Based on the error message this could to be related to the polymorphic bookmarks feature, [DEV: Re-add polymorphic bookmark columns by martin-brennan · Pull Request #16261 · discourse/discourse · GitHub](https://github.com/discourse/discourse/pull/16261) (ping @martin?).

After running into the trouble, my quick-and-dirty cure was to:

1. Comment out the line ` - exec: cd /var/www/discourse && sudo -E -u discourse bundle exec rake multisite:migrate` in the configuration file `containers/web_only.yml`.
2. Manually drop the (partially applied?) migrations related to bookmarks: `./launcher enter data` and use `psql` to log in to both my Discourse databases and run `ALTER TABLE bookmarks DROP COLUMN bookmarkable_id, DROP COLUMN bookmarkable_type;`
3. Re-run the rebuild: `./launcher rebuild web_only 2>&1`

What might I be missing now that the `multisite:migrate` was not executed? I’d appreciate any thoughts. Both sites seem to work though. 🤞

---

<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: [April 16, 2022, 10:18am UTC](https://meta.discourse.org/t/duplicatecolumn-and-multisite-migrate-failed/224480/2 "2022-04-16T10:18:58Z")

</div>

> [@jupiter](#):
>
> Both sites seem to work though.

Then I think what I would do is to run another upgrade and do if you’re out of the woods.

---

<div class="post-metadata">

### Author: ![jupiter](https://avatars.discourse-cdn.com/v4/letter/j/53a042/32.png) [@jupiter](https://meta.discourse.org/u/jupiter)
#### Post date: [April 16, 2022, 2:40pm UTC](https://meta.discourse.org/t/duplicatecolumn-and-multisite-migrate-failed/224480/3 "2022-04-16T14:40:20Z")

</div>

Any thoughts on why you’d do that? Or pointers to what to expect from running the multisite migrate? You see, I have an aversion to running scripts I don’t understand. 🙂

---

<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: [April 16, 2022, 7:53pm UTC](https://meta.discourse.org/t/duplicatecolumn-and-multisite-migrate-failed/224480/4 "2022-04-16T19:53:08Z")

</div>

> [@jupiter](#):
>
> Any thoughts on why you’d do that

Because you at least sort of know how to fix it and you’ll have forgotten completely when you upgrade the next time (if you are anything like me). I’m pretty sure that it’ll work, as I think that’s what others have seen when they fixed this issue

---

<div class="post-metadata">

### Author: ![martin](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/martin/32/491371_2.png) [@martin](https://meta.discourse.org/u/martin)
#### Post date: [April 18, 2022, 11:39pm UTC](https://meta.discourse.org/t/duplicatecolumn-and-multisite-migrate-failed/224480/5 "2022-04-18T23:39:32Z")

</div>

Makes sense, it seems like you never had run the post-migrate to remove the columns that were originally there, which I removed in [DEV: Re-add polymorphic bookmark columns by martin-brennan · Pull Request #16261 · discourse/discourse · GitHub](https://github.com/discourse/discourse/pull/16261). I may just need to check for the columns before re-adding them here [discourse/db/migrate/20220322024216\_add\_bookmark\_polymorphic\_columns.rb at 037172beaae0743176eee653bd2cd4cd1ce5c7e9 · discourse/discourse · GitHub](https://github.com/discourse/discourse/blob/037172beaae0743176eee653bd2cd4cd1ce5c7e9/db/migrate/20220322024216_add_bookmark_polymorphic_columns.rb) , will make a commit for that.

---

<div class="post-metadata">

### Author: ![martin](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/martin/32/491371_2.png) [@martin](https://meta.discourse.org/u/martin)
#### Post date: [April 19, 2022, 2:02am UTC](https://meta.discourse.org/t/duplicatecolumn-and-multisite-migrate-failed/224480/7 "2022-04-19T02:02:58Z")

</div>

Just merged a commit which should help:

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

---

<div class="post-metadata">

### Author: ![martin](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/martin/32/491371_2.png) [@martin](https://meta.discourse.org/u/martin)
#### Post date: [April 19, 2022, 2:03am UTC](https://meta.discourse.org/t/duplicatecolumn-and-multisite-migrate-failed/224480/8 "2022-04-19T02:03:01Z")

</div>


