運行Sinatra 1.0,我想添加一個數據庫表到我的程序。在我的Rakefile我有一個任務試圖使用ActiveRecord與Sinatra,遷移失敗問題
task :environment do
ActiveRecord::Base.establish_connection(YAML::load(File.open('config/database.yml'))["development"])
end
我有我的命名空間遷移任務調用遷移代碼:
namespace :related_products do
desc "run any migrations we may have in db/migrate"
task :migrate => :environment do
ActiveRecord::Migrator.migrate('db/migrate', ENV["VERSION"] ? ENV["VERSION"].to_i : nil)
end
我的控制檯pukes了一個錯誤,當調用的ActiveRecord ::遷移。 migrate()被創建。 rake中止! 未定義的方法'info'爲零:NilClass
遷移代碼本身非常簡單...並且沒有提示我這個缺失的信息類是什麼線索。
class CreateStores < ActiveRecord::Migration
def self.up
create_table :stores do |t|
t.string :name
t.string :access_url
t.timestamps
end
end
def self.down
drop_table :stores
end
end
我在這裏有點神祕,正在尋找一些線索,看看可能是錯的。謝謝!
簡單回溯顯示了進攻線僅僅是調用遷移:
rake aborted!
undefined method `info' for nil:NilClass
/Library/Ruby/Gems/1.8/gems/activerecord-2.3.5/lib/active_record/migration.rb:473:in `migrate'
/Library/Ruby/Gems/1.8/gems/activerecord-2.3.5/lib/active_record/migration.rb:472:in `each'
/Library/Ruby/Gems/1.8/gems/activerecord-2.3.5/lib/active_record/migration.rb:472:in `migrate'
/Library/Ruby/Gems/1.8/gems/activerecord-2.3.5/lib/active_record/migration.rb:400:in `up'
/Library/Ruby/Gems/1.8/gems/activerecord-2.3.5/lib/active_record/migration.rb:383:in `migrate'
/Users/baz/Documents/workspace/rp/Rakefile:26
/Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:636:in `call'
/Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:636:in `execute'
/Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:631:in `each'
/Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:631:in `execute'
/Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:597:in `invoke_with_call_chain'
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/monitor.rb:242:in `synchronize'
/Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:590:in `invoke_with_call_chain'
/Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:583:in `invoke'
/Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:2051:in `invoke_task'
/Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:2029:in `top_level'
/Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:2029:in `each'
/Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:2029:in `top_level'
/Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:2068:in `standard_exception_handling'
/Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:2023:in `top_level'
/Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:2001:in `run'
/Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:2068:in `standard_exception_handling'
/Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:1998:in `run'
/Library/Ruby/Gems/1.8/gems/rake-0.8.7/bin/rake:31
/usr/bin/rake:19:in `load'
/usr/bin/rake:19
我們能看到一個回溯?相關行似乎不在代碼中提供... – Matchu 2010-05-31 00:22:18
我添加了我得到的回溯。第26行只是調用ActiveRecord :: Migrator.migrate – 2010-05-31 00:43:36