Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails change primary id to 64 bit bigint

I am using rails and the mysql2 adapter. I want to change all primary ids and foreign keys to be 64 bit integers instead of the default 32 bit as they are right now for my production database.

Is this possible on the fly or do I have to drop the database, change the structure and import the data again?

If there is a way to do it without dropping the database, even if it's a hack, it would be great to know.

like image 663
Ybrin Avatar asked Jan 25 '17 15:01

Ybrin


1 Answers

Rails 5.1 already added a bigint type for migrations, you can do this:

change_column :users, :id, :bigint

Source: http://www.mccartie.com/2016/12/05/rails-5.1.html

like image 181
Edgar Ortega Avatar answered Sep 21 '22 08:09

Edgar Ortega