I would like to rename a table column from the rails console without writing any migration.
how can I do that?
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 ...
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.
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.
I opted to run this from the console:
ActiveRecord::Base.connection.rename_column :tablename, :old_column_name, :new_column_name
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With