Question

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?

Was it helpful?

Solution 2

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

OTHER TIPS

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top