質問

I have a table named project_updates and I am trying to rename a column in the table from update to updates. I ran rails g migration change_table and then edited the file like so:

class ChangeTable < ActiveRecord::Migration
  def change
    rename_column :project_updates, :update, :updates
  end
end

And then I run bundle exec rake db:migrate and nothing happens. I took the console to see the Model ProjectUpdate and it still has update rather than updates. What should I do?

役に立ちましたか?

解決 2

I had to delete the schema and run the rake command to generate once again. Not really sure why but it worked.

他のヒント

I think you should use up and down methods of Rails migration.

Edit the migration like this:

class ChangeTable < ActiveRecord::Migration
  def self.up
    rename_column :project_updates, :update, :updates
  end

  def self.down
    rename_column :project_updates, :updates, :update
  end

end

Probably check your Rails version, might be < Rails 3.1

change method of migration was introduced from Rails 3.1

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top