3

I have data in a Users table. One column called :provider_user_id of datatype float.

I want to change it to data type bigint.

How should I write this migration in rails 3

The original column was created with the following migration:

class AddFbuidToUsers < ActiveRecord::Migration
  def self.up
    add_column :users, :provider_user_id, :float
  end

  def self.down
    remove_column :users, :provider_user_id
  end
end
1

2 Answers 2

5
change_column :users, :provider_user_id, :bigint
Sign up to request clarification or add additional context in comments.

Comments

0

Add a new column of type bigint, any name will do.

Write an update loop to update each new bigint column with the value in your current column

Drop the old column (hopefully no RI on it).

Rename the new column to that of the just-dropped old column.

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.