Rails 5.1.0 introduces the bigint primary keys and foreign keys.
All new tables will have bigint pk and creating a reference migration to an old table will not work since the old pk is a normal int.
Using change_column _, :id,:bigint
just errors with a foreign key is pointing towards it, not to mention all the manual labour of finding all the tables and which has which key that needs to be modified.
How do I migrate my production database all my tables to use bigint pk and fk's?
Ofcourse since it's production rails db:drop rails db:setup
is not an option.
I facing the same problem. Temporary remove fk's should work. The goal is to change all primary keys from int to bigint.
class ChangeForeignKeysToBigInt < ActiveRecord::Migration[5.1]
def change
remove_foreign_key "event_users", "events"
change_column :event_users, :event_id, :bigint
change_column :events, :id, :bigint
add_foreign_key "event_users", "events"
end
end
you have to do that with all your tables and foreign key columns maybe handle indices the same way, i dont tested that
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With