Reputation: 1347
Below is the migration file I have defined to rename the column in schooling_document_types_managing_areas table but the issue is when I run the migration I am getting an error Index name is too long; the limit is 63 characters. Then I tried, something like
rename_column :schooling_document_types_managing_areas, :service_id, :managing_area_id, name: :index_schooling_documents_on_managing_area
then it returns
ArgumentError: wrong number of arguments (given 4, expected 3).
Any idea where I am going wrong
class RenameColumnName < ActiveRecord::Migration[5.1]
def up
rename_column :schooling_document_types_managing_areas, :service_id, :managing_area_id
end
def down
rename_column :schooling_document_types_managing_areas, :managing_area_id, :service_id
end
end
Upvotes: 1
Views: 327
Reputation: 12550
What about removing the index and re-adding it?
def change
remove_index :schooling_document_types_managing_areas, name: :index_schooling_document_types_managing_areas_on_service_id
rename_column :schooling_document_types_managing_areas, :service_id, :managing_area_id
add_index :schooling_document_types_managing_areas, name: :index_schooling_documents_on_managing_area
end
Also, I'm not sure about the nature of your data in production for that service_id
field, but keep in mind that just renaming isn't the safest way in case there are people using your app in the very exact moment that you're running your migration.
Upvotes: 2