2010-05-31 10 views
1

en cours d'exécution Sinatra 1.0, je voulais ajouter une table de base de données à mon programme. Dans mon Rakefile j'ai une tâcheen essayant d'utiliser ActiveRecord avec Sinatra, Migration échoue question

task :environment do 
    ActiveRecord::Base.establish_connection(YAML::load(File.open('config/database.yml'))["development"])  
end 

J'ai une tâche de migration dans mon espace de noms qui appelle le code de migration:

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 

Ma console pukes sur une erreur lors de l'appel à ActiveRecord :: Migrator. migrate() est créé. râteau abandonné! undefined la méthode `info 'pour nil: NilClass

Le code de migration lui-même est assez simple ... et ne me présente aucun indice quant à ce que cette classe d'information est manquant. Je suis un peu mystifié ici et je cherche des indices quant à ce qui pourrait ne pas être. Merci!

Un backtrace simple montre la ligne offensive est tout simplement l'appel à la migration:

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 
+0

Peut-on voir une trace? La ligne pertinente ne semble pas être dans le code fourni ... – Matchu

+0

J'ai ajouté la traçabilité que je reçois. La ligne 26 est simplement l'appel à ActiveRecord :: Migrator.migrate –

Répondre

3

Je viens de rencontrer dans ce même problème, et la solution était de donner ActiveRecord des informations sur l'endroit où les informations vous connecter la sortie.

j'ajouté ce qui suit à mon Rakefile

ActiveRecord::Base.logger = Logger.new(STDOUT) 
ActiveRecord::Migration.verbose = true 

-Timmy

+0

J'ai eu le problème exact (Heroku/Sinatra/AR) et cette solution a fonctionné parfaitement. Merci! –

+0

Merci pour cela. C'est bien d'avoir un problème résolu de cette façon. –