Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Renaming table in rails

I want to rename a table... (any table.)

I tried this line of code:

ActiveRecord::ConnectionAdapters::SchemaStatements.rename_table(old_name, new_name)

Here's the weird thing. I know I got it working the first time, but now I get this error: undefined method `rename_table' for ActiveRecord::ConnectionAdapters::SchemaStatements:Module

Was there something I need to set?

like image 312
Tommy Avatar asked Sep 28 '22 04:09

Tommy


People also ask

How do I rename a column in 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 ...


1 Answers

Remember that in Rails >= 3.1 you can use the change method.

 class RenameOldTableToNewTable < ActiveRecord::Migration
   def change
     rename_table :old_table_name, :new_table_name
   end 
 end
like image 300
Mikhail Grishko Avatar answered Oct 23 '22 10:10

Mikhail Grishko