By default rails set primary key column to int(11). But we had a situation where we need to increase size to bigint(20).

Now, Rails’ generic migration API doesn’t support that out of the box. So first let Rails generate PK column automatically. Next, we have to explicitly modify column using MySQL specific query using execute method.

Notice here, we have used up/down method instead of change. The reason being, execute method executes raw SQLs which is database dependent. So Rails has no idea how to reverse that operation and so it will throw Active Record::IrreversibleMigration when you rollback the migration.

Click here for more details…

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

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

Consulting is free – let us help you grow!