Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

how can I do that?

like image 382
Boti Avatar asked Sep 10 '14 13:09

Boti


People also ask

How do you rename a column in Ruby on Rails?

If you happen to have a whole bunch of columns to rename, or something that would have required repeating the table name over and over again: rename_column :table_name, :old_column1, :new_column1 rename_column :table_name, :old_column2, :new_column2 ...

How do you rename a column?

To change a column name, enter the following statement in your MySQL shell: ALTER TABLE table_name RENAME COLUMN old_column_name TO new_column_name; Replace table_name , old_column_name , and new_column_name with your table and column names.

How do I rename a column in SQL?

In Object Explorer, connect to an instance of Database Engine. In Object Explorer, right-click the table in which you want to rename columns and choose Rename. Type a new column name.


1 Answers

I opted to run this from the console:

ActiveRecord::Base.connection.rename_column :tablename, :old_column_name, :new_column_name
like image 193
Boti Avatar answered Sep 25 '22 12:09

Boti