这个问题也出现在使用自动化恢复测试的 discourse_docker 官方安装中,该测试每周每天早上通过流水线运行。这个类似的错误突然在失败的流水线中出现了。
I, [2026-05-20T07:59:01.413128 #1] INFO -- : > cd /var/www/discourse && su discourse -c 'bundle
exec rake db:migrate'
2026-05-20 07:59:09.214 UTC [1576] discourse@discourse ERROR: relation "translation_overrides" does not exist at character 523
2026-05-20 07:59:09.214 UTC [1576] discourse@discourse STATEMENT: SELECT a.attname, format_type(a.atttypid, a.atttypmod),
pg_get_expr(d.adbin, d.adrelid), a.attnotnull, a.atttypid, a.atttypmod,
c.collname, col_description(a.attrelid, a.attnum) AS comment,
attidentity AS identity,
attgenerated as attgenerated
FROM pg_attribute a
LEFT JOIN pg_attrdef d ON a.attrelid = d.adrelid AND a.attnum = d.adnum
LEFT JOIN pg_type t ON a.atttypid = t.oid
LEFT JOIN pg_collation c ON a.attcollation = c.oid AND a.attcollation <> t.typcollation
WHERE a.attrelid = '"translation_overrides"'::regclass
AND a.attnum > 0 AND NOT a.attisdropped
ORDER BY a.attnum
2026-05-20 07:59:13.167 UTC [1627] discourse@discourse ERROR: schema "discourse_functions" already exists
2026-05-20 07:59:13.167 UTC [1627] discourse@discourse STATEMENT: CREATE SCHEMA discourse_functions;
psql:/var/www/discourse/db/structure.sql:16: ERROR: schema "discourse_functions" already exists
rake aborted!
根本原因是恢复的备份与容器代码之间的版本不匹配。
最新的 Discourse 代码中包含一个引用 translation_overrides 的模型,但生产数据库(来自备份)处于较旧的版本,该表可能尚不存在或名称不同。
对我有效的方法是先重新构建(这会从头创建架构),然后恢复备份。恢复过程使用 Discourse 内置的恢复功能,它会正确删除并重新创建数据库。