我用下面的代碼字段director
添加到現有的movies
表:添加列到現有的表
class CreateMovies < ActiveRecord::Migration
def up
create_table :movies do |t|
t.string :title
t.string :rating
t.text :description
t.datetime :release_date
# Add fields that let Rails automatically keep track
# of when movies are added or modified:
t.timestamps
end
add_column :movies, :director, :string
end
def down
drop_table :movies
end
end
我已經看到this,但difrence是我堅持使用
rake db:test:prepare command after i add my new field.
當我運行rake db:test:prepare
,然後我跑我的cucumber
,它給我的erorr:
unknown attribute 'director' for Movie. (ActiveRecord::UnknownAttributeError)
,這意味着我無法在現場director
添加到table movies
, 那麼,什麼是錯在這裏?
檢查你已經把這個功能「導演」放在了參數中。 –
[將列添加到Rails遷移中的現有表](http://stackoverflow.com/questions/4834809/adding-a-column-to-an-existing-table-in-a-rails-移民) – weezing