# Can't rebuild container, "null value in column "score" violates not-null constraint"

**URL:** <https://meta.discourse.org/t/cant-rebuild-container-null-value-in-column-score-violates-not-null-constraint/112883>\
**Category:** Self-hosting\
**Created:** [29.Март.2019 01:48:17 UTC](https://meta.discourse.org/t/cant-rebuild-container-null-value-in-column-score-violates-not-null-constraint/112883 "2019-03-29T01:48:17Z")\
**Posts on this page:** 1\
**Showing post:** 1

<div class="post-metadata">

**Author:** ![jonathon](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jonathon/32/265865_2.png) [@jonathon](https://meta.discourse.org/u/jonathon)\
**Post date:** [29.Март.2019 01:48:17 UTC](https://meta.discourse.org/t/cant-rebuild-container-null-value-in-column-score-violates-not-null-constraint/112883/1 "2019-03-29T01:48:17Z")

</div>

After running `/var/discourse/launcher rebuild app` it looks like there’s an old “corrupted”/broken entry in the database:

```plaintext
I, [2019-03-29T11:29:05.642432 #14] INFO -- : > cd /var/www/discourse && su discourse -c 'bundle exec rake db:migrate'
2019-03-29 11:29:17.018 UTC [435] discourse@discourse ERROR: null value in column "score" violates not-null constraint
2019-03-29 11:29:17.018 UTC [435] discourse@discourse DETAIL: Failing row contains (2147, ReviewableFlaggedPost, 4, 2554, f, null, null, 72, 4721, null, f,
 23604, Post, 2554, {}, 0, null, 2016-07-07 15:27:19.377128, 2016-07-07 15:27:19.377128).
2019-03-29 11:29:17.018 UTC [435] discourse@discourse STATEMENT: UPDATE reviewables SET score = (
          SELECT SUM(score)
          FROM reviewable_scores
          WHERE reviewable_scores.reviewable_id = reviewables.id
        )

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

PG::NotNullViolation: ERROR: null value in column "score" violates not-null constraint
DETAIL: Failing row contains (2147, ReviewableFlaggedPost, 4, 2554, f, null, null, 72, 4721, null, f, 23604, Post, 2554, {}, 0, null, 2016-07-07 15:27:19.3
77128, 2016-07-07 15:27:19.377128).
: UPDATE reviewables SET score = (
  SELECT SUM(score)
  FROM reviewable_scores
  WHERE reviewable_scores.reviewable_id = reviewables.id
)

```

This is causing the bootstrap process to fail, leaving me with a broken Discourse instance.

How can I fix this? e.g. how can I get into the database to fix or remove this row?

As part of the `rebuild` step the old `app` container was destroyed; can I fix this without a running container with PostgreSQL10? The Ubuntu 16.04 host OS has Postgres 9.5 in the repo, would this still be able to open the database if I install it?

Edit:

The older/existing docker image is still present:

```plaintext
$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
local_discourse/app latest 403b9aa4125e 4 days ago 2.37GB
discourse/base 2.0.20190321-0122 7db99586b5b5 8 days ago 1.97GB
discourse/base 2.0.20190217 9c24db193c37 5 weeks ago 1.92GB

```

This should mean it’s possible to `start` a new container with that image, which should at least let me get in to fix the database…

Edit 2:

After editing `launcher` to have `rebuild)` skip `set_existing_container` and `run_bootstrap`, `rebuild app` got the forum back up. I thought I’d tried `start app` and it complained the configuration didn’t exist, but I don’t know why there would be a difference… In any event, I have a running container.

---

_[View the full topic](https://meta.discourse.org/t/cant-rebuild-container-null-value-in-column-score-violates-not-null-constraint/112883)._
