0

I am going into my ruby console with

ruby c

Then I type in

rename_column :table_name :old_column :new_column

where table_name old_column and new_column is replaced with the correct attributes

After I click enter, I receive the following error:

    SyntaxError ((irb):1: syntax error, unexpected ':', expecting end-of-input)
rename_column :table_name ^:old_column :new_column
  • Why aren't you using a migration for that? – jvillian Dec 06 '18 at 22:53
  • Possible duplicate of [How can I rename a database column in a Ruby on Rails migration?](https://stackoverflow.com/questions/1992019/how-can-i-rename-a-database-column-in-a-ruby-on-rails-migration) – ray Dec 07 '18 at 13:57
  • As pointed out your format is not correct for a ruby command, but even with a correct format there is no `main:Object` method `rename_column`. You can't do that in the console. See Jay Dorsey's answer for how to do this change. – SteveTurczyn Dec 07 '18 at 13:58

3 Answers3

1

You need to generate a migration.

rails generate migration ChangeColumnFoo

Open the file in db/migrate folder that it says was created.

Add a new line after the def change line and add your rename:

rename_column :table_name, :old_column, :new_column

Save the file then run rake db:migrate from the console.

Jay Dorsey
  • 3,563
  • 2
  • 18
  • 24
0

You are missing some commas:

Original:

rename_column :table_name :old_column :new_column

Edited:

rename_column :table_name, :old_column, :new_column
user1158559
  • 1,954
  • 1
  • 18
  • 23
0

you forgot the commas :

rename_column :table_name, :old_column, :new_column
Theo
  • 51
  • 8