Maximus S
Maximus S

Reputation: 11095

Rails: Editing Model Column

I'm not sure why it happened, but one of the columns starts with a capital letter. I'm a little worried to change it by doing migrations because the affected column is 'comment_id' column, and Comment is this model's parent.

 id | has_voted | Comment_id | created_at | updated_at
----+-----------+------------+------------+------------
(0 rows)

this belongs to comment model. Is it okay to drop Comment_id and simply adding comment_id column by generating new migrations? Or should I fix it somewhere else?

Upvotes: 1

Views: 455

Answers (1)

gabrielhilal
gabrielhilal

Reputation: 10769

You can generate a new migration file:

  rails g migration FixColumnName

Now, edit the file ../migrate/fix_column_name.rb and change the table_name for the real name of your table.

  class FixColumnName < ActiveRecord::Migration
    def change
    rename_column :table_name, :Comment_id, :comment_id
    end
  end

source: How can I rename a database column in a Ruby on Rails migration?

Upvotes: 2

Related Questions