문제

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