2

RAILS_ENV=staging bundle exec rake db:migrate --trace を使用してステージングで次の移行を実行しようとしています

class UpdateDatabaseForPayments < ActiveRecord::Migration
  def change
    # Create the plans
    Plan.create(:name => "Student")
    Plan.create(:name => "Professional")
    Plan.create(:name => "Studio")
    # create_subscription just creates a subscription the user, 
    # nothing out of the ordinary there.
    User.all.each do |u|
      u.create_subscription
    end
  end
end

移行ファイル名は 20130121190404_update_database_for_payments.rb です。

これは次のエラーで失敗します。

uninitialized constant UpdateDatabaseForPayments::Plan
/home/ubuntu/apps/teamup/releases/20130121204425/db/migrate/20130121190404_update_database_for_payments.rb:4:in `change'
/home/ubuntu/apps/teamup/shared/bundle/ruby/1.9.1/gems/activerecord-3.2.11/lib/active_record/migration.rb:407:in `block (2 levels) in migrate'
/home/ubuntu/.rvm/rubies/ruby-1.9.3-p327-turbo/lib/ruby/1.9.1/benchmark.rb:280:in `measure'
/home/ubuntu/apps/teamup/shared/bundle/ruby/1.9.1/gems/activerecord-3.2.11/lib/active_record/migration.rb:407:in `block in migrate'
/home/ubuntu/apps/teamup/shared/bundle/ruby/1.9.1/gems/activerecord-3.2.11/lib/active_record/connection_adapters/abstract/connection_pool.rb:129:in `with_connection'
/home/ubuntu/apps/teamup/shared/bundle/ruby/1.9.1/gems/activerecord-3.2.11/lib/active_record/migration.rb:389:in `migrate'
/home/ubuntu/apps/teamup/shared/bundle/ruby/1.9.1/gems/activerecord-3.2.11/lib/active_record/migration.rb:528:in `migrate'
/home/ubuntu/apps/teamup/shared/bundle/ruby/1.9.1/gems/activerecord-3.2.11/lib/active_record/migration.rb:720:in `block (2 levels) in migrate'
/home/ubuntu/apps/teamup/shared/bundle/ruby/1.9.1/gems/activerecord-3.2.11/lib/active_record/migration.rb:777:in `call'
/home/ubuntu/apps/teamup/shared/bundle/ruby/1.9.1/gems/activerecord-3.2.11/lib/active_record/migration.rb:777:in `ddl_transaction'
/home/ubuntu/apps/teamup/shared/bundle/ruby/1.9.1/gems/activerecord-3.2.11/lib/active_record/migration.rb:719:in `block in migrate'
/home/ubuntu/apps/teamup/shared/bundle/ruby/1.9.1/gems/activerecord-3.2.11/lib/active_record/migration.rb:700:in `each'
/home/ubuntu/apps/teamup/shared/bundle/ruby/1.9.1/gems/activerecord-3.2.11/lib/active_record/migration.rb:700:in `migrate'
/home/ubuntu/apps/teamup/shared/bundle/ruby/1.9.1/gems/activerecord-3.2.11/lib/active_record/migration.rb:570:in `up'
/home/ubuntu/apps/teamup/shared/bundle/ruby/1.9.1/gems/activerecord-3.2.11/lib/active_record/migration.rb:551:in `migrate'
/home/ubuntu/apps/teamup/shared/bundle/ruby/1.9.1/gems/activerecord-3.2.11/lib/active_record/railties/databases.rake:179:in `block (2 levels) in <top (required)>'
/home/ubuntu/apps/teamup/shared/bundle/ruby/1.9.1/gems/rake-10.0.3/lib/rake/task.rb:228:in `call'
/home/ubuntu/apps/teamup/shared/bundle/ruby/1.9.1/gems/rake-10.0.3/lib/rake/task.rb:228:in `block in execute'
/home/ubuntu/apps/teamup/shared/bundle/ruby/1.9.1/gems/rake-10.0.3/lib/rake/task.rb:223:in `each'
/home/ubuntu/apps/teamup/shared/bundle/ruby/1.9.1/gems/rake-10.0.3/lib/rake/task.rb:223:in `execute'
/home/ubuntu/apps/teamup/shared/bundle/ruby/1.9.1/gems/rake-10.0.3/lib/rake/task.rb:166:in `block in invoke_with_call_chain'
/home/ubuntu/.rvm/rubies/ruby-1.9.3-p327-turbo/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize'
/home/ubuntu/apps/teamup/shared/bundle/ruby/1.9.1/gems/rake-10.0.3/lib/rake/task.rb:159:in `invoke_with_call_chain'
/home/ubuntu/apps/teamup/shared/bundle/ruby/1.9.1/gems/rake-10.0.3/lib/rake/task.rb:152:in `invoke'
/home/ubuntu/apps/teamup/shared/bundle/ruby/1.9.1/gems/rake-10.0.3/lib/rake/application.rb:143:in `invoke_task'
/home/ubuntu/apps/teamup/shared/bundle/ruby/1.9.1/gems/rake-10.0.3/lib/rake/application.rb:101:in `block (2 levels) in top_level'
/home/ubuntu/apps/teamup/shared/bundle/ruby/1.9.1/gems/rake-10.0.3/lib/rake/application.rb:101:in `each'
/home/ubuntu/apps/teamup/shared/bundle/ruby/1.9.1/gems/rake-10.0.3/lib/rake/application.rb:101:in `block in top_level'
/home/ubuntu/apps/teamup/shared/bundle/ruby/1.9.1/gems/rake-10.0.3/lib/rake/application.rb:110:in `run_with_threads'
/home/ubuntu/apps/teamup/shared/bundle/ruby/1.9.1/gems/rake-10.0.3/lib/rake/application.rb:95:in `top_level'
/home/ubuntu/apps/teamup/shared/bundle/ruby/1.9.1/gems/rake-10.0.3/lib/rake/application.rb:73:in `block in run'
/home/ubuntu/apps/teamup/shared/bundle/ruby/1.9.1/gems/rake-10.0.3/lib/rake/application.rb:160:in `standard_exception_handling'
/home/ubuntu/apps/teamup/shared/bundle/ruby/1.9.1/gems/rake-10.0.3/lib/rake/application.rb:70:in `run'
/home/ubuntu/apps/teamup/shared/bundle/ruby/1.9.1/gems/rake-10.0.3/bin/rake:33:in `<top (required)>'
/home/ubuntu/apps/teamup/shared/bundle/ruby/1.9.1/bin/rake:23:in `load'
/home/ubuntu/apps/teamup/shared/bundle/ruby/1.9.1/bin/rake:23:in `<main>'
Tasks: TOP => db:migrate

さて、奇妙なことは、

  • この移行は、ステージング環境のローカル コピーで問題なく実行されます
  • Rails コンソールから問題なく計画を作成できます。

ファイルの名前を少しいじってみましたが、何をしても同じエラーです。

4

3 に答える 3

1

そのため、Rails 4 では標準になる予定のステージングでスレッド セーフを有効にしていたことが問題であることがわかりました。どうやらオートローディングはスレッド セーフではなく、これがモデルがロードされなかった理由です。 エラーについては、こちらでも説明しています。 修正は、次を設定することです

config.threadsafe! unless $rails_rake_task

ここでモンセフ・ベルヤマニが示したように。

また、移行、シード ファイル、または失敗しているその他のレーキ タスクでモデルを明示的に要求することで修正することもできます。

于 2013-01-22T19:13:46.963 に答える
1

Planモデルを含むコードをデプロイします。Planエラーが示唆するように、モデルが見つかりません。

編集:

これが実際に当てはまるかどうかを証明するために、失敗した移行の先頭に次を配置できます。

Rails.application.eager_load!
ActiveRecord::Base.descendants.each {|d| puts d.name}

これにより、基本的に Rails が認識しているモデルのリストが出力されます。私はあなたがPlanそれらの中から見つけられないと予測しています。私の好奇心を満たすために、次のようにも言えます。puts Dir.glob("app/models/*.rb").map{|p| p.sub("app/models/","")}

于 2013-01-22T16:11:19.143 に答える
0

申し訳ありませんが、これを投稿せざるを得ませんでした。

ここに画像の説明を入力してください

移行は、DBスキーマを変更するためのものです。データはseeds.rbに作成する必要があります。

于 2013-01-22T16:07:39.477 に答える