Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to rename an index using a rails migration?

I know that there is a rename_column transformation, but it seems that rename_index does not exist.

Do I have to use remove_index and add_index instead?

like image 667
hectorsq Avatar asked Mar 06 '09 20:03

hectorsq


People also ask

Can I rename migration file Rails?

You can change the migration file name, but you have to perform a few steps: rake db:rollback to the point that queries table is rolled back. Now change the name of migration file, also the contents. Change the name of any Model that may use the table.

How do you rename an index?

Click the plus sign to expand the table on which you want to rename an index. Click the plus sign to expand the Indexes folder. Right-click the index you want to rename and select Rename. Type the index's new name and press Enter.

What can Rails migration do?

A Rails migration is a tool for changing an application's database schema. Instead of managing SQL scripts, you define database changes in a domain-specific language (DSL). The code is database-independent, so you can easily move your app to a new platform.

What is index in Rails migration?

An index is used to speed up the performance of queries on a database. Rails allows us to create index on a database column by means of a migration. By default, the sort order for the index is ascending. But consider the case where we are fetching reports from the database.


1 Answers

rename_index should be given strings and not symbols.

rename_index :table_name, 'old_name', 'new_name' 

Had me scratching my head for a while when trying to rename a table and it's indexes. Rails 3.2.3 and MySQL.

like image 57
Nothus Avatar answered Sep 16 '22 20:09

Nothus