How do you write a migration to rename an ActiveRecord model and its table in Rails?

前端 未结 5 1477
忘掉有多难
忘掉有多难 2020-11-29 14:56

I\'m terrible at naming and realize that there are a better set of names for my models in my Rails app.
Is there any way to use a migration to rename a model and its cor

5条回答
  •  感情败类
    2020-11-29 15:33

    In Rails 4 all I had to do was the def change

    def change
      rename_table :old_table_name, :new_table_name
    end
    

    And all of my indexes were taken care of for me. I did not need to manually update the indexes by removing the old ones and adding new ones.

    And it works using the change for going up or down in regards to the indexes as well.

提交回复
热议问题