Railsアプリを4.2から5.1にアップグレードしようとしています。Rails 5:db:migrateがglobalize gemで失敗PG :: UndefinedTable
私が現在使用していた宝石:
- 宝石 'のActiveRecord、' 5.1.4
- 宝石 'グローバル化'、 '5.1.0.beta2'
を私のGemfileで:
gem 'globalize', git: 'https://github.com/globalize/globalize'
gem 'activemodel-serializers-xml'
gem 'globalize-accessors'
gem 'globalize3_helpers', git: 'https://github.com/mathieumahe/globalize3_helpers.git'
次のような移行ファイルがあります。
class CreateQuotas < ActiveRecord::Migration[5.0]
def change
create_table :quotas do |t|
t.references :survey, index: true
t.integer :target, default: 0
t.timestamps null: false
end
reversible do |dir|
dir.up { Quota.create_translation_table!(title: :string) }
dir.down { Quota.drop_translation_table! }
end
end
end
し、適切なtranslations
ディレクティブはquota.rbモデルに設定されている:移行を実行
class Quota < ApplicationRecord
# ...
translates :title
# ...
end
は、次のようなエラーが生じている:
rails aborted!
StandardError: An error has occurred, this and all later migrations canceled:
PG::UndefinedTable: ERROR: relation "quota" does not exist
LINE 8: WHERE a.attrelid = '"quota"'::regclass
^
: 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 = '"quota"'::regclass
AND a.attnum > 0 AND NOT a.attisdropped
ORDER BY a.attnum
私がやっています間違っていたり、何かが分かりにくいのですか?
UPDATE:
私はこの上でいくつかの進歩を遂げてきました。 SQLをマイグレーションに直接入力したので、次のようになります。
class CreateQuotas < ActiveRecord::Migration[5.0]
def change
create_table :quotas do |t|
t.references :survey, index: true
t.integer :target, default: 0
t.timestamps null: false
end
reversible do |dir|
dir.up do
execute <<-SQL
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 = '"quotas"'::regclass
AND a.attnum > 0 AND NOT a.attisdropped
ORDER BY a.attnum
SQL
end
# dir.up do
# Quota.create_translation_table! :title => :string
# end
#
dir.down do
Quota.drop_translation_table!
end
end
end
end
これは動作するようです。
本質的に、Quota.create_translation_table! :title => :string
ディレクティブは、障害の原因となる'"quota"'::regclass
を特異化しています。これは、クラス名から推測されていない'"quotas"'::regclass
、と渡し:/
それは違いはありません:( – DaniG2k
@ DaniG2k何日前に、私はバージョンなしでマイグレーションを使用したとき同じエラーが発生しました: 'ActiveRecord :: Migration' –
私が既に持っているもの' class CreateQuotas
DaniG2k