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?

3
  • If you drop the column, the data in it will be lost (unless you copy it first). Commented Nov 21, 2012 at 9: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? Commented Nov 21, 2012 at 9:30
  • Or you could just rename the column: api.rubyonrails.org/classes/ActiveRecord/Migration.html. I'm not sure how it will work in this case. Are column names case-sensitive? Commented Nov 21, 2012 at 9:32

1 Answer 1

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?

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.