Change Column Name Rails


Answer :

Run in your console:

$ rails g migration rename_season_to_season_id 

Now file db/migrate/TIMESTAMP_rename_season_to_season_id.rb contains following:

class RenameSeasonToSeasonId < ActiveRecord::Migration   def change   end end 

Modify it as follows:

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

Then run $ rake db:migrate in console.


Either fix your migration and do

rake db:rollback db:migrate 

or make another migration like so:

rename_column :shoes, :season, :season_id if column_exists?(:shoes, :season) && !column_exists?(:shoes, :season_id) 

and then do

rake db:migrate 

Comments

Popular posts from this blog

Are Regular VACUUM ANALYZE Still Recommended Under 9.1?

Can Feynman Diagrams Be Used To Represent Any Perturbation Theory?