change column name Rails

后端 未结 4 1580
南旧
南旧 2021-02-02 10:18

I have this table:

class CreateShoes < ActiveRecord::Migration
  def change
    create_table :shoes do |t|
      t.string :name
      t.boolean :leather
              


        
4条回答
  •  隐瞒了意图╮
    2021-02-02 11:02

    If your branch has been pushed to production then one probably needs to add the new migration by running the following command:

    rails g migration RenameSeasonColumnNameToShoes

    and if it hasn't been pushed to production or you have to currently make changes to your branch only, then do:

    bundle exec rake db:rollback

    Then make changes to your migration file inside /db/migrate/

    Then in your migration file, using rename_column do as follows:

    class RenameSeasonColumnNameToShoes < ActiveRecord::Migration
      def change
          rename_column :shoes, :season, :season_id
      end
    end
    

    and then do

    bundle exec rake db:migrate db:test:prepare

提交回复
热议问题