# Duplicate key value violates unique constraint on a table during upgrade

**URL:** https://meta.discourse.org/t/duplicate-key-value-violates-unique-constraint-on-a-table-during-upgrade/154132
**Category:** Self-hosting
**Created:** [June 7, 2020, 11:54pm UTC](https://meta.discourse.org/t/duplicate-key-value-violates-unique-constraint-on-a-table-during-upgrade/154132 "2020-06-07T23:54:30Z")
**Posts on this page:** 1
**Showing post:** 5

<div class="post-metadata">

### Author: ![Steven](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/steven/32/187890_2.png) [@Steven](https://meta.discourse.org/u/Steven)
#### Post date: [June 8, 2020, 2:36pm UTC](https://meta.discourse.org/t/duplicate-key-value-violates-unique-constraint-on-a-table-during-upgrade/154132/5 "2020-06-08T14:36:44Z")

</div>

Thanks, I ran the command, no error mentionned. I’ll try another rebuild in a few hour and I’ll see

edit : ok the reindex didn’t do anything

1 migrations failed!

```
Failed to migrate default
#<ActiveRecord::RecordNotUnique: PG::UniqueViolation: ERROR: duplicate key value violates unique constraint "index_screened_ip_addresses_on_ip_address"
DETAIL: Key (ip_address)=(10.0.0.0/8) already exists.
>

```

I restarted the app, cleaned all the ip in `/admin/logs/screened_ip_addresses`, and **upgraded successfully**.

The ip are back, didn’t have to add them manually

 ![image](https://global.discourse-cdn.com/meta/original/3X/9/2/92960a8408091de6bf9be1e8919f9209cbaf8fb6.png)

Maybe I took a little too much caution, but since it’s not my forum, I didn’t want to mess things up. Thanks @pfaffman for the help!

I guess I’ll see next time if it happens again but at least I’ll know how to fix it

---

_[View the full topic](https://meta.discourse.org/t/duplicate-key-value-violates-unique-constraint-on-a-table-during-upgrade/154132)._
