0

運行命令,而我收到以下錯誤獲取建設任務的錯誤,同時運行耙分貝:遷移在軌道3

rake db:migrate VERSION=201504******. 

錯誤:

rake aborted!
Don't know how to build task '20150419131135'

其實我有一個遷移文件already.Now我連接到一個新的數據庫。在這裏我想創建該數據庫中的表。請檢查我的下面的文件。

20150419131135_create_users.rb

class CreateUsers < ActiveRecord::Migration 
    def self.up 
    if !table_exists? :users 
     create_table :users do |t| 
     t.string :contact_name 
     t.string :login_id 
     t.string :password_hash 
     t.string :password_salt 
     t.string :phone 
     t.string :address 
     t.timestamps 
     end 
    end 
    end 
end 


class CreateUsers < ActiveRecord::Migration 
    def self.down 
    drop_table :users if !table_exists?(:users) 
    end 
end 

遷移完成後,本我得到了上述error.Please幫我解決這個錯誤。

+0

什麼,當你做到這'耙分貝約:migrate'(不含版) – jphager2

回答

0

self.downself.up方法應在一個CreateUsersclass

class CreateUsers < ActiveRecord::Migration 
    def self.up 
     create_table :users do |t| 
     t.string :contact_name 
     t.string :login_id 
     t.string :password_hash 
     t.string :password_salt 
     t.string :phone 
     t.string :address 
     t.timestamps 
     end unless table_exists? :users 
    end 
    end 

    def self.down 
    drop_table :users if table_exists? :users 
    end 
end 
+0

它不應該只是上下(instsnce方法) – jphager2

+0

@ jphager2:在文檔中Rails 2.3中的遷移是用'self'編寫的,自3.2開始,它們沒有寫入。 – potashin

+0

好的。這個問題指定了Rails 3,所以這可能是問題所在? – jphager2