Rails : Create a drop table cascade migration
You could always run raw SQL in the migration.
MYSQL:
execute "DROP TABLE #{:table_name} CASCADE CONSTRAINTS PURGE"
PostgreSQL:
execute "DROP TABLE #{:table_name} CASCADE"
You can check the documentation of the built-in method drop_table
here.
In Rails 4 you can do the following:
drop_table :accounts, force: :cascade
Put a file in your initializers directory called postgres.rb then did. This works for rails 4.1 anyway.
module ActiveRecord
module ConnectionAdapters # :nodoc:
module SchemaStatements
def drop_table(table_name, options = {})
execute "DROP TABLE #{quote_table_name(table_name)} CASCADE"
end
end
end
end