2014-11-05 48 views
0

我正在使用ruby 1.8.7和rails 1.2.6。 (它的老我知道,但我必須使用它。)我需要添加列到用戶表。我無法使用rails生成與rails 1.2.6的遷移。我需要添加一個版本化的數據庫遷移文件。我怎樣才能做到這一點? 我想將產品列添加到用戶表中。我使用以下內容在db/migrate文件夾中創建了一個文件。在rails 1.2.6(舊版本)中添加列到數據庫表

class AddProductToUser < ActiveRecord::Migration 
    def self.up 
     add_column :users, :product, :string 
    end 
    def self.down 
     remove_column :users, :product 
    end 
end 

我用script/generate migration AddProductToUser。它給出的錯誤爲 undefined method 'cache' for Gem:Module

有關如何在rails 1.2.6(< 2.x)中運行遷移的任何指示也很有用。

回答

0

你的遷移文件看起來(幾乎)很好,文件名是否與類名相匹配,並且它是否在前面的遷移中有一個序列號?

稍有變化:

# db/migrate/123_add_product_to_user.rb 
class AddProductToUser < ActiveRecord::Migration 
    def self.up 
    add_column :users, :product, :string 
    end 

    def self.down 
    remove_column :users, :product # note sure where radius came from? 
    end 
end 

那麼應該只用rake migrate

More info at apidock

+0

我得到了如下錯誤運行。使用'rake migrate'後。 '耙子中止了! NoMethodError:未定義方法'緩存'爲Gem:模塊 '。文件名正確,版本爲'142_add_product_to_user.rb' – 2014-11-05 10:19:06