Sinatra中Active Record迁移的奇怪错误

时间:2011-04-03 03:33:23

标签: activerecord sinatra

以下是我在辛特拉迁移的Rakefile。我跑的时候遇到了2个奇怪的错误

未初始化的常量记录器(在线ActiveRecord :: Base.logger = Logger.new(STDOUT))

无法将String转换为Integer(在线ActiveRecord :: Migrator.migrate('db / migrate'))

namespace :db do

 task :environment do
  require 'active_record'
  ActiveRecord::Base.establish_connection :adapter => 'mysql2', :port => '/Applications/MAMP/tmp/mysql/mysql.sock'
 end

 desc "Migrate the database"
 task(:migrate => :environment) do
  #ActiveRecord::Base.logger = Logger.new(STDOUT)
  ActiveRecord::Migration.verbose = true
  ActiveRecord::Migrator.migrate('db/migrate')
 end
end

有谁知道如何解决这些问题?感谢。

1 个答案:

答案 0 :(得分:4)

uninitialized constant Logger

在使用之前将Logger类包含在Ruby标准库中:require 'logger'