Ruby on rails 5.1 upgrade, cannot name index

156 Views Asked by At

I'm upgrading to rails 5.1 but my migrations are failing due to an index name being too long.

Error:

ArgumentError: Index name 'index_mailboxer_notifications_on_notified_object_type_and_notified_object_id' on table 'mailboxer_notifications' is too long; the limit is 63 characters

The index name automatically gets created, but I should be able to name it by using the name: command.

Migration.rb

add_index :mailboxer_notifications, [:notified_object_id, :notified_object_type],
    name: 'index_mailboxer_notifications_on_notified_object_id_and_type'

But the name: command seems to be getting ignored. Has this changed in rails 5.1? Is there any other way to name the index?

1

There are 1 best solutions below

0
Thanh On

In case index name is too long and migration is failed to run, it should not create any index.

Try drop index on notified_object_id, notified_object_type columns if it is exists and run migration with index name again.