Is it mandatory to separately remove the foreign keys / indexes if you are planning to drop the table

StackOverflow https://stackoverflow.com/questions/8093051

Question

Is it mandatory to separately remove the foreign keys / indexes, if you are planning to drop the table. Since dropping the table seems to be removing foreign keys / indexes.

I am using this gem http://github.com/matthuhiggins/foreigner to remove the create / remove foreign keys / indexes. add_foreign_key seems to create foreign_key and an index. Does that mean I should remove the index / foreign key separately on self.down OR can I just drop the table?

No correct solution

OTHER TIPS

When you drop the table, everything goes. That is, the table and all dependent objects (indexes, constraints, triggers) are dropped in one go.

Note that the drop will fail if other objects that depends on this table (such as schema bound views, the "1" side in an FK etc)

No. It just drops everything and works - including FK that refer to other tables.

It will fail if there are other tables with FK refering to this table, of course.
But that is a different matter.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top