i18n-active_record PG :: Error:ERROR:リレーション "translations"が存在しません(rails 4)

マルコ・ユリンチッチ

Railsのgemに少し問題があります。i18n-active_record gemをインストールしました(rails4とruby2を使用)。私のgemファイルで

    gem 'i18n-active_record',
        :git => 'git://github.com/svenfuchs/i18n-active_record.git',
        :require => 'i18n/active_record'

これにはモデルの変換も必要なので、モデルと移行を生成しました

    class CreateTranslations < ActiveRecord::Migration
      def self.up
        create_table :translations do |t|
          t.string :locale
          t.string :key
          t.text   :value
          t.text   :interpolations
          t.boolean :is_proc, :default => false

          t.timestamps
        end
      end

      def self.down
        drop_table :translations
      end
    end

これでバンドルインストールを実行でき、gemがインストールされます。しかし、rake db:migrateを実行しようとすると、エラーが発生します

    PG::Error: ERROR:  relation "translations" does not exist (and some other stuff)

私のローカルサーバーでは、最初に移行を実行し、次にgemをgemfileに追加して、バンドルインストールを実行することでこの問題を回避しました。ただし、gemはgemfileに含まれていてはなりません。存在する場合、gemファイルが最新ではないため、rakemigrateを実行できません。

しかし、今はこれをHeroku(または他のサーバー)にプッシュしたいので、毎回これを実行したくありません。このループを回避する方法はありますか?

編集

githubで答えを得ました。私はただする必要がありました:

    require 'i18n/backend/active_record'

    if ActiveRecord::Base.connection.table_exists? 'translations'
      I18n.backend = I18n::Backend::ActiveRecord.new

      I18n::Backend::ActiveRecord.send :include, I18n::Backend::Memoize
      I18n::Backend::ActiveRecord.send :include, I18n::Backend::Flatten
      I18n::Backend::Simple.send :include, I18n::Backend::Memoize
      I18n::Backend::Simple.send :include, I18n::Backend::Pluralization

      I18n.backend = I18n::Backend::Chain.new I18n::Backend::Simple.new, I18n.backend
    end
マルコ・ユリンチッチ

私はこれを解決しました。初期化子(locale.rb)にifテーブルが存在する場合に追加する必要がありました。

  require 'i18n/backend/active_record'

    if ActiveRecord::Base.connection.table_exists? 'translations'
      I18n.backend = I18n::Backend::ActiveRecord.new

      I18n::Backend::ActiveRecord.send :include, I18n::Backend::Memoize
      I18n::Backend::ActiveRecord.send :include, I18n::Backend::Flatten
      I18n::Backend::Simple.send :include, I18n::Backend::Memoize
      I18n::Backend::Simple.send :include, I18n::Backend::Pluralization

      I18n.backend = I18n::Backend::Chain.new I18n::Backend::Simple.new, I18n.backend
    end

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

Rails 4 / i18n /ロケールを別のページに渡すことができません

分類Dev

PG :: UndefinedTable-エラー:リレーション "active_storage_attachments"が存在しません

分類Dev

PG :: UndefinedTable:エラー:リレーション "active_storage_blobs"が存在しません

分類Dev

i18n rails4の製造エラー。開発ではありません

分類Dev

PG :: UndefinedTable:エラー:リレーション "action_text_rich_texts"が存在しません| Rails 6 | Rails_Admin | Postgresql

分類Dev

heroku postgresql database rails app PG :: UndefinedTable:エラー:リレーション「コメント」が存在しません

分類Dev

ActiveRecord :: StatementInvalid(PG :: UndefinedTable:エラー:リレーション "guestbooks"が存在しません

分類Dev

PG::UndefinedTable: エラー: リレーション 'caves' が存在しません

分類Dev

NuxtJS i18n [vue-router] about_us ___ enという名前のルートが存在しません

分類Dev

Ruby on Rails4とSimpleFormの「ヘルパー」で利用可能なi18n翻訳のリスト?

分類Dev

Rails:i18nをRails 4列挙型で使用する方法

分類Dev

PG :: UndefinedTable:エラー:リレーション ""は存在しません-AmazonEC2、Postgresql、およびRails 5

分類Dev

Railsはckeditorを生成します:install --orm = active_record --backend = active_storagが機能しませんRails5

分類Dev

PG :: UndefinedTable:エラー:リレーション "..."は存在しません

分類Dev

PG :: UndefinedColumn:エラー:リレーション「events」の列「city_id」が存在しません

分類Dev

I18nルート:必要なキーがありません:[:locale]

分類Dev

Rails 5.1.5 PG 10.0.0 PG :: UndefinedFunctionの取得:エラー:関数gen_random_uuid()が存在しません

分類Dev

ActionView :: Template :: Error(PG :: UndefinedFunction:ERROR:演算子が存在しません:整数~~不明

分類Dev

ActionView :: Template :: Error(PG :: UndefinedColumn:ERROR:columnposts.user_idが存在しません

分類Dev

I18nロケールを使用したRails言語名

分類Dev

Rails 4 I18nはロケールを誤って認識します: 'language-conuntry' as: 'language' like: 'zh-CN' as:zh

分類Dev

I18n translation with i18n-active_record: same form for same key

分類Dev

Rails ActiveRecord :: StatementInvalid:PG :: UndefinedTable:エラー:リレーション "pg_range"が存在しません行3:pg_rangeをr ON oid = rngtypidとして左結合します

分類Dev

各ドメインi18nロケールにロケールが設定されたRails4マルチドメインアプリケーション

分類Dev

Rails i18nロケール固有の構成設定?

分類Dev

i18nテキスト更新言語がスクリプトで機能しませんでした

分類Dev

Ruby on Rails `method_missing ':未定義のメソッドʻactive_record'

分類Dev

Rails 4.2.3 `method_missing ':未定義のメソッド` active_record'

分類Dev

ActiveRecordの予期しないi18nエラー

Related 関連記事

  1. 1

    Rails 4 / i18n /ロケールを別のページに渡すことができません

  2. 2

    PG :: UndefinedTable-エラー:リレーション "active_storage_attachments"が存在しません

  3. 3

    PG :: UndefinedTable:エラー:リレーション "active_storage_blobs"が存在しません

  4. 4

    i18n rails4の製造エラー。開発ではありません

  5. 5

    PG :: UndefinedTable:エラー:リレーション "action_text_rich_texts"が存在しません| Rails 6 | Rails_Admin | Postgresql

  6. 6

    heroku postgresql database rails app PG :: UndefinedTable:エラー:リレーション「コメント」が存在しません

  7. 7

    ActiveRecord :: StatementInvalid(PG :: UndefinedTable:エラー:リレーション "guestbooks"が存在しません

  8. 8

    PG::UndefinedTable: エラー: リレーション 'caves' が存在しません

  9. 9

    NuxtJS i18n [vue-router] about_us ___ enという名前のルートが存在しません

  10. 10

    Ruby on Rails4とSimpleFormの「ヘルパー」で利用可能なi18n翻訳のリスト?

  11. 11

    Rails:i18nをRails 4列挙型で使用する方法

  12. 12

    PG :: UndefinedTable:エラー:リレーション ""は存在しません-AmazonEC2、Postgresql、およびRails 5

  13. 13

    Railsはckeditorを生成します:install --orm = active_record --backend = active_storagが機能しませんRails5

  14. 14

    PG :: UndefinedTable:エラー:リレーション "..."は存在しません

  15. 15

    PG :: UndefinedColumn:エラー:リレーション「events」の列「city_id」が存在しません

  16. 16

    I18nルート:必要なキーがありません:[:locale]

  17. 17

    Rails 5.1.5 PG 10.0.0 PG :: UndefinedFunctionの取得:エラー:関数gen_random_uuid()が存在しません

  18. 18

    ActionView :: Template :: Error(PG :: UndefinedFunction:ERROR:演算子が存在しません:整数~~不明

  19. 19

    ActionView :: Template :: Error(PG :: UndefinedColumn:ERROR:columnposts.user_idが存在しません

  20. 20

    I18nロケールを使用したRails言語名

  21. 21

    Rails 4 I18nはロケールを誤って認識します: 'language-conuntry' as: 'language' like: 'zh-CN' as:zh

  22. 22

    I18n translation with i18n-active_record: same form for same key

  23. 23

    Rails ActiveRecord :: StatementInvalid:PG :: UndefinedTable:エラー:リレーション "pg_range"が存在しません行3:pg_rangeをr ON oid = rngtypidとして左結合します

  24. 24

    各ドメインi18nロケールにロケールが設定されたRails4マルチドメインアプリケーション

  25. 25

    Rails i18nロケール固有の構成設定?

  26. 26

    i18nテキスト更新言語がスクリプトで機能しませんでした

  27. 27

    Ruby on Rails `method_missing ':未定義のメソッドʻactive_record'

  28. 28

    Rails 4.2.3 `method_missing ':未定義のメソッド` active_record'

  29. 29

    ActiveRecordの予期しないi18nエラー

ホットタグ

アーカイブ