升级失败:UniqueViolation:重复键值违反了唯一约束 "data_explorer_queries_pkey"

今天的升级到最新版本失败:

FAILED
--------------------
Pups::ExecError: cd /var/www/discourse && su discourse -c 'bundle exec rake db:migrate' 执行失败,返回码为 #<Process::Status: pid 3194 exit 1>
失败位置:/pups/lib/pups/exec_command.rb:112:in `spawn'
执行失败时的参数:{"cd"=>"$home", "hook"=>"db_migrate", "cmd"=>["su discourse -c 'bundle exec rake db:migrate'"]}
590cf0611c566ea6df5f70ffdd2cec2359e84eaea29b7abcde77d56288a46370
** 启动失败 ** 请向上滚动日志,查找更早的错误信息,可能不止一条。

日志上方内容:

原因:
PG::UniqueViolation: 错误:重复键值违反了唯一约束 "data_explorer_queries_pkey"
详情:键 (id)=(-10) 已存在。

以及

rake 执行中断!
StandardError: 发生错误,本次及后续所有迁移已取消:

错误:重复键值违反了唯一约束 "data_explorer_queries_pkey"
详情:键 (id)=(-10) 已存在。

因此,我估计需要删除重复的 data_explorer_queries_pkey 键。

该如何操作?

1 个赞
3 个赞

谢谢,但我无法进入应用:

./launcher enter app
来自守护进程的错误响应:容器 694b24a2a235e90456fb0ca770c86ac14bb914ad33ada8a18fc4777a1188d848 未运行
root@gaoa-discourse:/var/discourse#

另外:

root@gaoa-discourse:/var/discourse# su - postgres
用户 'postgres' 没有密码条目
1 个赞

那么,重启容器?

./launcher start app

然后,你需要执行类似以下的命令:

./launcher enter app

接着:

su postgres -c 'psql discourse'

4 个赞

谢谢!不确定为什么我第一次尝试时没有启动。

看起来我有一个重复的 “10” ID:

4374 | discourse-data-explorer | q:-10 | JSON      | {"id":-10,"name":"Inactive Users with no posts","description":"analyze pre-Discourse signups.","sql":"SELECT\
n    u.id,\n    u.username_lower AS \"username\",\n    u.created_at,\n    u.last_seen_at\nFROM users u\nWHERE u.active = false\nORDER BY u.id\n","created_by":"-1",
"created_at":null,"group_ids":[],"last_run_at":"2019-10-21T04:03:35.548+00:00"}

4114 | discourse-data-explorer | q:-10 | JSON      | {"id":-10,"name":"Inactive Users with no posts","description":"analyze pre-Discourse signups.","sql":"SELECT\
n    u.id,\n    u.username_lower AS \"username\",\n    u.created_at,\n    u.last_seen_at\nFROM users u\nWHERE u.active = false\nORDER BY u.id\n","created_by":"-1",
"created_at":null,"last_run_at":"2019-02-27T06:17:48.317+00:00"}

所以我想我应该运行这个:

DELETE from plugin_store_rows WHERE id = 10

还是应该是:

DELETE from plugin_store_rows WHERE id = -10

我很好奇——上面的命令会删除哪一个?是它找到的第一个,还是两个都会删除?

1 个赞

ID 列中的数字是 43744114。请删除编号较大的那个。

切勿运行 DELETE from plugin_store_rows WHERE id = 10!!否则您将删除错误的条目!

3 个赞

啊,是这个?

DELETE from plugin_store_rows WHERE id = 4374;

1 个赞

是的。在 PL/SQL 查询输出中,您应该能看到正确的列标题,对吧?

1 个赞

既然你提到了,是的。我向下滚动是因为输出是这样的:

2 个赞

是的,另外,通常建议在提交前运行命令以查看其影响,请参阅:

这样,如果您发现自己误删了 500 行数据而不是仅删除一行,您仍有机会回滚而无需担心。

3 个赞

成功!:tada: 感谢 @merefield 的指导。

我的 DELETE 命令缺少一个闭合的分号(已在上文更新)。

3 个赞

哦,没错,这总是让我中招 :wink:

3 个赞

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.