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 5955459
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T18:07:01+00:00 2026-05-22T18:07:01+00:00

I need to move some columns from one existing table to another. How do

  • 0

I need to move some columns from one existing table to another. How do I do it using a rails migration?

class AddPropertyToUser < ActiveRecord::Migration
  def self.up
    add_column :users, :someprop, :string
    remove_column :profiles, :someprop
  end

  def self.down
    add_column :profiles, :someprop, :string
    remove_column :users, :someprop
  end
end

The above just creates the new columns, but values are left empty…

I want to avoid logging in to the database to manually update the tables.

If there is a way to move column values programmatically, what are the performance characteristics? Would it do row-by-row, or is there a way to update in bulk?

  • 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-22T18:07:02+00:00Added an answer on May 22, 2026 at 6:07 pm

    I ended up using this migration (tested, it works, and rolls back successfully):

    class AddPropertyToUser < ActiveRecord::Migration
      def self.up
        add_column :users, :someprop, :string
        execute "UPDATE users u, profiles p SET u.someprop = p.someprop WHERE u.id = p.user_id"
        remove_column :profiles, :someprop
      end
    
      def self.down
        add_column :profiles, :someprop, :string
        execute "UPDATE profiles p, users u SET p.someprop = u.someprop WHERE p.user_id = u.id"
        remove_column :users, :someprop
      end
    end
    

    I like it because it avoids the row-by-row updates on a large database.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to move some data from a table to a archive table. Now
I need to know how to move a image from one location to another
I need to move data from a datareader into a Farpoint Spreadsheet component in
I need to move a folder from a plugin to the main app/views. I
I need to move a huge amount of data from a couple tables in
Good morning! I need to move data from Oracle 8i(Enterprise Edition Release 8.1.6.0.0) to
I try to move some dos command from my batch file into python but
I'm new to EF 4.1 and try to move some code from to EF
I'm trying to move some old code from hand-made persistence to Hibernate. The issue
We need to move off traditional FTP for security purposes (it transmits it's passwords

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.