1

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

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.