Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I migrate a database column from integer to bigint in rails?

Based on what I've found, I'm using this right now, but it's not working...

def change
 change_column :users, :twitter_id, :integer, :limit => 8
end
like image 266
Carl Avatar asked Oct 20 '15 00:10

Carl


People also ask

How do I migrate a specific migration in Rails?

To run a specific migration up or down, use db:migrate:up or db:migrate:down . The version number in the above commands is the numeric prefix in the migration's filename. For example, to migrate to the migration 20160515085959_add_name_to_users. rb , you would use 20160515085959 as the version number.

How Rails db Migrate works?

When you run db:migrate, rails will check a special table in the database which contains the timestamp of the last migration applied to the database. It will then apply all of the migrations with timestamps after that date and update the database table with the timestamp of the last migration.

What is migrate in Ruby on Rails?

Migrations are a convenient way to alter your database schema over time in a consistent way. They use a Ruby DSL so that you don't have to write SQL by hand, allowing your schema and changes to be database independent. You can think of each migration as being a new 'version' of the database.


1 Answers

I just ran into the same issue. The following worked for me:

def up 
  change_column :my_table, :my_column, :bigint
end
like image 179
malikilam Avatar answered Oct 12 '22 02:10

malikilam