# Dubbele data explorer sleutel blokkeert rebuild

**URL:** <https://meta.discourse.org/t/duplicate-data-explorer-key-blocking-rebuild/162375>\
**Category:** Product Support\
**Created:** [28 augustus 2020 om 18:38 UTC](https://meta.discourse.org/t/duplicate-data-explorer-key-blocking-rebuild/162375 "2020-08-28T18:38:50Z")\
**Posts on this page:** 1\
**Showing post:** 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:** [28 augustus 2020 om 18:38 UTC](https://meta.discourse.org/t/duplicate-data-explorer-key-blocking-rebuild/162375/1 "2020-08-28T18:38:51Z")

</div>

Hey all,

Rare I ask for help, but I’m puzzled about how to resolve this.

Just rebuilt my site and getting this:

```plaintext
discourse-data-explorer is already at latest compatible version

I, [2020-08-28T17:53:57.578920 #1] INFO -- : > cd /var/www/discourse && su discourse -c 'bundle exec rake db:migrate'
2020-08-28 17:54:07.380 UTC [3060] discourse@discourse ERROR: duplicate key value violates unique constraint "data_explorer_queries_pkey"
2020-08-28 17:54:07.380 UTC [3060] discourse@discourse DETAIL: Key (id)=(-7) already exists.
2020-08-28 17:54:07.380 UTC [3060] discourse@discourse STATEMENT: INSERT INTO data_explorer_queries(id, name, description, sql, user_id, last_run_at, hidden, created_at, updated_at)
        SELECT
          (replace(key, 'q:',''))::integer,
          value::json->>'name',
          value::json->>'description',
          value::json->>'sql',
          CASE WHEN (value::json->'created_by')::text = 'null' THEN
            null
          WHEN (value::json->'created_by')::text = '""' THEN
            null
          WHEN (value::jsonb ? 'created_by') THEN
            (value::json->>'created_by')::integer
          ELSE
            null
          END,
          CASE WHEN (value::json->'last_run_at')::text = 'null' THEN
            null
          WHEN (value::json->'last_run_at')::text = '""' THEN
            null
          ELSE
            (value::json->'last_run_at')::text::timestamptz
          END,
          CASE WHEN (value::json->'hidden')::text = 'null' THEN
            false
          WHEN (value::jsonb ? 'hidden') THEN
            (value::json->'hidden')::text::boolean
          ELSE
            false
          END,
          '2020-08-28 17:54:07.368132',
          '2020-08-28 17:54:07.368132'
        FROM plugin_store_rows
        WHERE plugin_name = 'discourse-data-explorer' AND type_name = 'JSON' AND (replace(key, 'q:',''))::integer < 0

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

ERROR: duplicate key value violates unique constraint "data_explorer_queries_pkey"

```

The important part being `ERROR: duplicate key value violates unique constraint "data_explorer_queries_pkey"`

I’ve found the query with the id -7 on the rails console, but it seems like one of the built in queries.

```plaintext
[5] pry(main)> DataExplorer::Query.find(-7)
=> #<DataExplorer::Query:0x000055e44bbb4038
 @created_by="-1",
 @description="based on post score calculated using reply count, likes, incoming links, bookmarks, time spent and read count.",
 @group_ids=[],
 @hidden=nil,
 @id=-7,
 @last_run_at="2020-01-03T18:06:31.966+00:00",
 @name="Top 50 Quality Users",
 @sql=
  "SELECT sum(p.score) / count(p) AS \"average score per post\",\n count(p.id) AS post_count,\n p.user_id\nFROM posts p\nJOIN users u ON u.id = p.user_id\nWHERE p.created_at >= CURRENT_DATE - INTERVAL '6 month'\nAND NOT u.admin\nAND u.active\nGROUP BY user_id,\n u.views\nHAVING count(p.id) > 50\nORDER BY sum(p.score) / count(p) DESC\nLIMIT 50">

```

I’ve also got into the plsql prompt but not sure - should I be removing a built in query to allow it to insert a new one?

---

_[View the full topic](https://meta.discourse.org/t/duplicate-data-explorer-key-blocking-rebuild/162375)._
