How can I rename a column from rails console without migration?

I would like to rename a table column from the rails console without a migration entry.

How can i do this?

+5
source share
3 answers
rails dbconsole ALTER TABLE name RENAME column TO column 
+4
source

I decided to run this from the console:

 ActiveRecord::Base.connection.rename_column :tablename, :old_column_name, :new_column_name 
+16
source
  • you start the console: rails g migration ChangeColName
  • you edit the file db / migrate / "timestamp" _change_col_name.rb paste in def change -

     rename_column :tablename, :old_column_name, :new_column_name -save 
  • you start the console: rake db:migrate

0
source

Source: https://habr.com/ru/post/1202239/


All Articles