# Migration error: \`ActiveRecord::NotNullViolation: PG::NotNullViolation: ERROR: column "private\_message" contains null values\`

**URL:** <https://meta.discourse.org/t/migration-error-activerecord-pg-error-column-private-message-contains-null-values/161304>\
**Category:** Product Support\
**Created:** [18 augustus 2020 om 18:52 UTC](https://meta.discourse.org/t/migration-error-activerecord-pg-error-column-private-message-contains-null-values/161304 "2020-08-18T18:52:32Z")\
**Posts on this page:** 1\
**Showing post:** 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:** [18 augustus 2020 om 18:52 UTC](https://meta.discourse.org/t/migration-error-activerecord-pg-error-column-private-message-contains-null-values/161304/1 "2020-08-18T18:52:32Z")

</div>

I’m doing an upgrade on a site and it’s failing with `PG::NotNullViolation: ERROR: column "private_message" contains null values`. I can’t find where the `private_message` column exists. There are no non-official plugins.

oh. Wait. Here’s this:

```plaintext
(See full trace by running task with --trace)                                                                                            
I, [2020-08-18T18:19:13.253667 #1] INFO -- : == 20200818084329 UpdatePrivateMessageOnPostSearchData: migrating ============= 
-- execute("DELETE FROM post_search_data\nWHERE post_id IN (\n SELECT posts.id\n FROM posts\n LEFT JOIN topics ON topics.id = posts.topic_id\n WHERE topics.id IS NULL\n)\n")
   -> 21.9072s                                                                                                       
-- execute("DELETE FROM post_search_data\nWHERE post_id IN (\n SELECT post_search_data.post_id\n FROM post_search_data\n LEFT JOIN posts ON posts.id = post_search_data.post_id\n WHERE posts.id IS NULL\n)\n")                                                                       
   -> 47.2663s
-- execute("UPDATE post_search_data\nSET private_message = true\nFROM posts\nINNER JOIN topics ON topics.id = posts.topic_id AND topics.archetype = 'private_message'\nWHERE posts.id = post_search_data.post_id\n")                                                                      
   -> 107.2137s             
-- execute("UPDATE post_search_data\nSET private_message = false\nFROM posts\nINNER JOIN topics ON topics.id = posts.topic_id AND topics.archetype <> 'private_message'\nWHERE posts.id = post_search_data.post_id\n")
   -> 834.3738s                                                                                                                              
-- change_column_null(:post_search_data, :private_message, false)

```

Hey @tgxworld, I think this might be due to

[https://github.com/discourse/discourse/commit/2161abfabd433774de4698ddc89d716217c104e2](https://github.com/discourse/discourse/commit/2161abfabd433774de4698ddc89d716217c104e2)

---

_[View the full topic](https://meta.discourse.org/t/migration-error-activerecord-pg-error-column-private-message-contains-null-values/161304)._
