1

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?

Maximus S
  • 10,759
  • 19
  • 75
  • 154
  • If you drop the column, the data in it will be lost (unless you copy it first). – Sergio Tulentsev Nov 21 '12 at 09:27
  • It's okay since I don't have any data yet. So would it be okay to drop it and add the correct column in this case? – Maximus S Nov 21 '12 at 09:30
  • Or you could just rename the column: http://api.rubyonrails.org/classes/ActiveRecord/Migration.html. I'm not sure how it will work in this case. Are column names case-sensitive? – Sergio Tulentsev Nov 21 '12 at 09:32

1 Answers1

2

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?

Community
  • 1
  • 1
gabrielhilal
  • 10,660
  • 6
  • 54
  • 81