I had to delete the schema and run the rake command to generate once again. Not really sure why but it worked.
Schema: Editing a column name of a table using 'rename column'
-
21-07-2023 - |
문제
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 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
제휴하지 않습니다 StackOverflow