PG::UndefinedTable: ERROR: relation "translation_overrides" does not exist

AI-generated summary

Users are reporting a PG::UndefinedTable error regarding the missing translation_overrides relation during Discourse database migrations. jamesarobbo initially encountered this issue while attempting to run migrations on a production Heroku setup, noting that a similar problem was reportedly fixed previously. zogstrip suggested dropping and recreating the database, but jamesarobbo clarified that this is a production environment.

marcosbc identified the issue as a known problem affecting fresh startups in Kubernetes clusters and vanilla Discourse launcher setups. They provided logs showing the error occurring during rake db:migrate when the system attempts to query the translation_overrides table before it is fully established.

Eric_Keller provided a definitive root cause for automated restore pipelines: a version mismatch between the restored database backup and the current container code. The latest code references the translation_overrides model, but the older backup does not contain this table. The suggested solution is to rebuild the application first to create the necessary schema from scratch, and then perform the restore. This approach allows Discourse’s built-in restore process to properly handle the database structure, avoiding the migration conflict.

I have cloned master and in trying to run migrations i get this error:

ActiveRecord::StatementInvalid: PG::UndefinedTable: ERROR: relation “translation_overrides” does not exist

I see that a topic was created for this last November and seemingly fixed so i’m wondering what coudl be the cause?

ActiveRecord::StatementInvalid: PG::UndefinedTable: ERROR:  relation "translation_overrides" does not exist
remote:        LINE 5:                WHERE a.attrelid = '"translation_overrides"':...
remote:        ^
remote:        :               SELECT a.attname, format_type(a.atttypid, a.atttypmod),
remote:        pg_get_expr(d.adbin, d.adrelid), a.attnotnull, a.atttypid, a.atttypmod
remote:        FROM pg_attribute a LEFT JOIN pg_attrdef d
remote:        ON a.attrelid = d.adrelid AND a.attnum = d.adnum
remote:        WHERE a.attrelid = '"translation_overrides"'::regclass
remote:        AND a.attnum > 0 AND NOT a.attisdropped
remote:        ORDER BY a.attnum


PG::UndefinedTable: ERROR:  relation "translation_overrides" does not exist
remote:        LINE 5:                WHERE a.attrelid = '"translation_overrides"':...

thanks

Is that a dev setup? If so, then run “rake db:drop db:create db:migrate” again.

production but getting it to run on heroku (i realise that heroku is not the ‘supported’, ‘recommended’ setup :slight_smile: ). despite that, do you have any ideas? thanks a lot

こんにちは皆さん、これは Migration error on fresh startup running in k8s cluster と同じ問題のようです。また、公式の standalone.yml テンプレート を使用した純粋な Discourse ランチャー環境で、デプロイ時にこの問題を再現することができました。

$ ./launcher rebuild app
...
I, [2021-05-27T10:53:27.612150 #1]  INFO -- : > cd /var/www/discourse && su discourse -c 'bundle exec rake plugin:pull_compatible_all'
I, [2021-05-27T10:53:30.072954 #1]  INFO -- : docker_manager はすでに最新互換バージョンです

I, [2021-05-27T10:53:30.073194 #1]  INFO -- : > cd /var/www/discourse && su discourse -c 'bundle exec rake db:migrate'

2021-05-27 10:53:32.977 UTC [4354] discourse@discourse ERROR:  文字位置 454 で、リレーション "translation_overrides" が存在しません
2021-05-27 10:53:32.977 UTC [4354] 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
	  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

警告: oid 19 の型 "name" に対して型キャストが定義されていません。今後の変更に対して安全であるためには、この型を明示的に TEXT にキャストしてください。
> テーマとカラースキームのシードを開始
I, [2021-05-27T10:53:49.976589 #1]  INFO -- : == 20000225050318 AddSchemaMigrationDetails: 移行中 ========================
...

これは、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 の組み込み復元機能を使用し、データベースを適切に削除して再作成します。