我正在创建一个简单的用户表,当我运行 rake db:migrate 时,它出现在 create_table(:users) 但是我同时收到以下警告。我尝试再次运行 rake db:migrate,然后在此页面上出现第二个错误。如何检查表是否已创建,以及如何防止出现此警告/错误?
错误 1
WARNING: 'require 'rake/rdoctask'' is deprecated. Please use 'require 'rdoc/task' (in RDoc 2.4.2+)' instead.
at /Users/anderskitson/.rvm/gems/ruby-1.9.2-p290@rails3tutorial/gems/rake-0.9.2.2/lib/rake/rdoctask.rb
WARNING: Global access to Rake DSL methods is deprecated. Please include
... Rake::DSL into classes and modules which use the Rake DSL methods.
WARNING: DSL method DemoApp::Application#task called at /Users/anderskitson/.rvm/gems/ruby-1.9.2-p290@rails3tutorial/gems/railties-3.0.1/lib/rails/application.rb:214:in `initialize_tasks'
错误 2
rake aborted!
undefined local variable or method `d' for main:Object
这就是我用 --trace 得到的结果
/Users/anderskitson/rails_project/demo_app/Rakefile:1:in `<top (required)>'
/Users/anderskitson/.rvm/gems/ruby-1.9.2-p290@rails3tutorial/gems/rake-0.9.2.2/lib/rake/rake_module.rb:25:in `load'
/Users/anderskitson/.rvm/gems/ruby-1.9.2-p290@rails3tutorial/gems/rake-0.9.2.2/lib/rake/rake_module.rb:25:in `load_rakefile'
/Users/anderskitson/.rvm/gems/ruby-1.9.2-p290@rails3tutorial/gems/rake-0.9.2.2/lib/rake/application.rb:501:in `raw_load_rakefile'
/Users/anderskitson/.rvm/gems/ruby-1.9.2-p290@rails3tutorial/gems/rake-0.9.2.2/lib/rake/application.rb:82:in `block in load_rakefile'
/Users/anderskitson/.rvm/gems/ruby-1.9.2-p290@rails3tutorial/gems/rake-0.9.2.2/lib/rake/application.rb:133:in `standard_exception_handling'
/Users/anderskitson/.rvm/gems/ruby-1.9.2-p290@rails3tutorial/gems/rake-0.9.2.2/lib/rake/application.rb:81:in `load_rakefile'
/Users/anderskitson/.rvm/gems/ruby-1.9.2-p290@rails3tutorial/gems/rake-0.9.2.2/lib/rake/application.rb:65:in `block in run'
/Users/anderskitson/.rvm/gems/ruby-1.9.2-p290@rails3tutorial/gems/rake-0.9.2.2/lib/rake/application.rb:133:in `standard_exception_handling'
/Users/anderskitson/.rvm/gems/ruby-1.9.2-p290@rails3tutorial/gems/rake-0.9.2.2/lib/rake/application.rb:63:in `run'
/Users/anderskitson/.rvm/gems/ruby-1.9.2-p290@rails3tutorial/gems/rake-0.9.2.2/bin/rake:33:in `<top (required)>'
/Users/anderskitson/.rvm/gems/ruby-1.9.2-p290@rails3tutorial/bin/rake:19:in `load'
/Users/anderskitson/.rvm/gems/ruby-1.9.2-p290@rails3tutorial/bin/rake:19:in `<main>'
我跑了
rails generate scaffold User name:string email:string
然后我跑了
rake db:migrate
我的 rake 文件看起来像
d# Add your own tasks in files placed in lib/tasks ending in .rake,
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
require File.expand_path('../config/application', __FILE__)
require 'rake'
DemoApp::Application.load_tasks
最佳答案
删除 Rakefile 中的第一个字符 d
:
d# Add your own tasks in files placed in lib/tasks ending in .rake,
您会认出这一行,因为它是您粘贴的错误消息中指向的行号,您可以看出那是该行的错误部分,因为它正是错误消息告诉您它不能的字母'识别。
关于ruby-on-rails - rake 数据库 :migrate fails,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9102681/