Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 519069
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T08:00:09+00:00 2026-05-13T08:00:09+00:00

I wrongly named a column hased_password instead of hashed_password . How do I update

  • 0

I wrongly named a column hased_password instead of hashed_password.

How do I update the database schema, using migration to rename this column?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T08:00:09+00:00Added an answer on May 13, 2026 at 8:00 am
    rename_column :table, :old_column, :new_column
    

    You’ll probably want to create a separate migration to do this. (Rename FixColumnName as you will.):

    bin/rails generate migration FixColumnName
    # creates  db/migrate/xxxxxxxxxx_fix_column_name.rb
    

    Then edit the migration to do your will:

    # db/migrate/xxxxxxxxxx_fix_column_name.rb
    class FixColumnName < ActiveRecord::Migration
      def self.up
        rename_column :table_name, :old_column, :new_column
      end
    
      def self.down
        # rename back if you need or do something else or do nothing
      end
    end
    

    For Rails 3.1 use:

    While, the up and down methods still apply, Rails 3.1 receives a change method that "knows how to migrate your database and reverse it when the migration is rolled back without the need to write a separate down method".

    See "Active Record Migrations" for more information.

    rails g migration FixColumnName
    
    class FixColumnName < ActiveRecord::Migration
      def change
        rename_column :table_name, :old_column, :new_column
      end
    end
    

    If you happen to have a whole bunch of columns to rename, or something that would have required repeating the table name over and over again:

    rename_column :table_name, :old_column1, :new_column1
    rename_column :table_name, :old_column2, :new_column2
    ...
    

    You could use change_table to keep things a little neater:

    class FixColumnNames < ActiveRecord::Migration
      def change
        change_table :table_name do |t|
          t.rename :old_column1, :new_column1
          t.rename :old_column2, :new_column2
          ...
        end
      end
    end
    

    Then just db:migrate as usual or however you go about your business.


    For Rails 4:

    While creating a Migration for renaming a column, Rails 4 generates a change method instead of up and down as mentioned in the above section. The generated change method is:

    $ > rails g migration ChangeColumnName
    

    which will create a migration file similar to:

    class ChangeColumnName < ActiveRecord::Migration
      def change
        rename_column :table_name, :old_column, :new_column
      end
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How can you create a temporary FIFO (named pipe) in Python? This should work:
I'm using the following code to write data through a named pipe from one
I happened to write this: <input type=hdnStatus name=hidden value=1 /> Instead of: <input type=hidden
I have a bunch of classes I want to rename. Some of them have
I have the following structure: MyClass { guid ID guid ParentID string Name }
I'm having trouble doing an aggregation query on a many-to-many related field. Here are
I'm doing simple tests on all files in directory. But from some reason, sometimes,
I'm trying to send a multipart/alternative MIME e-mail via PHP script ... all works
I have the following line in a view: <%= f.select(:province_id, options_from_collection_for_select(Province.find(:all, :conditions => {

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.