2012-02-01 168 views
1

我創建一個簡單的用戶表,當我跑耙db:遷移它似乎create_table(:用戶)Howerver我同時得到以下警告。我試着運行rake數據庫:再次遷移,然後我得到了第二個錯誤在這個頁面上。如何檢查表是否已創建,以及如何防止此警告/錯誤?耙db:遷移失敗

ERROR1

WARNING: 'require 'rake/rdoctask'' is deprecated. Please use 'require 'rdoc/task' (in RDoc 2.4.2+)' instead. 
    at /Users/anderskitson/.rvm/gems/[email protected]/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/[email protected]/gems/railties-3.0.1/lib/rails/application.rb:214:in `initialize_tasks' 

ERROR 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/[email protected]/gems/rake-0.9.2.2/lib/rake/rake_module.rb:25:in `load' 
/Users/anderskitson/.rvm/gems/[email protected]/gems/rake-0.9.2.2/lib/rake/rake_module.rb:25:in `load_rakefile' 
/Users/anderskitson/.rvm/gems/[email protected]/gems/rake-0.9.2.2/lib/rake/application.rb:501:in `raw_load_rakefile' 
/Users/anderskitson/.rvm/gems/[email protected]/gems/rake-0.9.2.2/lib/rake/application.rb:82:in `block in load_rakefile' 
/Users/anderskitson/.rvm/gems/[email protected]/gems/rake-0.9.2.2/lib/rake/application.rb:133:in `standard_exception_handling' 
/Users/anderskitson/.rvm/gems/[email protected]/gems/rake-0.9.2.2/lib/rake/application.rb:81:in `load_rakefile' 
/Users/anderskitson/.rvm/gems/[email protected]/gems/rake-0.9.2.2/lib/rake/application.rb:65:in `block in run' 
/Users/anderskitson/.rvm/gems/[email protected]/gems/rake-0.9.2.2/lib/rake/application.rb:133:in `standard_exception_handling' 
/Users/anderskitson/.rvm/gems/[email protected]/gems/rake-0.9.2.2/lib/rake/application.rb:63:in `run' 
/Users/anderskitson/.rvm/gems/[email protected]/gems/rake-0.9.2.2/bin/rake:33:in `<top (required)>' 
/Users/anderskitson/.rvm/gems/[email protected]/bin/rake:19:in `load' 
/Users/anderskitson/.rvm/gems/[email protected]/bin/rake:19:in `<main>' 

我跑

軌生成腳手架用戶名:字符串email:字符串

然後我跑

rake db:migrate 

我耙文件看起來像

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

你可以添加有問題的遷移到你的問題。 – 2012-02-01 20:46:07

+0

我很抱歉,我不確切地知道您的意思 – 2012-02-01 20:53:03

+0

爲您嘗試運行的遷移添加代碼。 – bensie 2012-02-01 21:02:55

回答

4

取出d這是你的Rakefile的第一個字符:

d# Add your own tasks in files placed in lib/tasks ending in .rake, 

,因爲它是它指出,在您粘貼錯誤消息的行號你會認識到這條線,你可以告訴大家,這是該行的錯誤部分,因爲這正是錯誤消息告訴你它無法識別的字母。

+0

的輸出,修復了我的問題的一半。我的數據庫成功創建,但我仍然得到所有的警告消息,爲什麼會這樣。 – 2012-02-02 00:25:00

0

這取決於on Rails的版本你目前使用的,但我建議生成一個新的Rails應用程序,並複製生成的Rakefile,以確保你達到dat即那裏可能有require "rake/rdoctask"需要改變。

也就是說,此警告可能不會導致遷移失敗。

--trace再次運行以獲得完整的堆棧跟蹤。

+0

我添加了--trace – 2012-02-01 20:51:48