1

Hi I have a model or table called bluedarts but I want to change the name to "staging" and also add couples of columns to the same table. Whats the command to do it.

1 Answer 1

2

Migrations would be the answer here: http://guides.rubyonrails.org/migrations.html. You will need the rename_table method.

rails g migration rename_bluedarts_to_staging


def change
  rename_table :bluedarts, :staging
end

Then specify in the model that needs to use this table that it needs to use the staging table:

set_table_name 'staging'

To add the columns, create another migration for each column.

rails g migration add_column_name_to_staging column_name:string

The column_name:string bit says what the column name should be, and what type it should be. Then you just run rake db:migrate. Because of the naming convention used in the migration, it knows what code to use to add the column properly.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.