Does drop_table also remove_index?

Well, the title pretty much says it all, but here it is again: will
drop_table also remove any indexes for that table? Or do we need to
specify each index in the down migration?

I tried looking through the drop_table documentation, but didn’t see
it mentioned. I also checked some of the more popular open source
projects, and they just drop_table, but don’t remove any indexes.
Maybe rails takes care of this as part of its “magic” ?

That is a database function. Dropping a table will also drop the
indexes (at least for MySQL and SQL Server).

Foreign key constraints are another issue. If you have added them
(i.e. via foreign_key_migrations), you would have to explicitly remove
them in your down migration before dropping the parent table.

The database itself probably deletes indices for tables that no longer
exist. You should check your database’s documentation to be sure.

~David

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs