I had a situation where I had to use different primary key column name over the default one (id) Rails provide.

As per the official guide:

By default, create_table will create a primary key called id. You can change the name of the primary key with the :primary_key option (don’t forget to update the corresponding model) or, if you don’t want a primary key at all, you can pass the option id: false.

So I set :primary_key option in create_table and it worked.

Here is the Generated DDL in MySQL

Now I need the primary key column to be type of bigint(20) instead of default int(11).

I created another migration to modify column type and width of primary key.

This migration correctly changes the type but drops AUTO_INCREMENT from the table definition.

I looked around again and landed to an issue which helped me to fix the issue.

To make the above migration work, you need to install activerecord-mysql-awesome gem first. However I was not convinced to use this gem.

One more change would require to make it work is to set primary_key into your model.

Click here for more details…


At BoTree Technologies, we build enterprise applications with our RoR team of 25+ engineers.

We also specialize in RPA, AI, Python, Django, JavaScript and ReactJS.

Consulting is free – let us help you grow!