How do I force a DROP TABLE CASCADE in a Rails 3.2 migration?
Is there an option to pass to drop_table(\"table_name\")?
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
In Rails 4 you can do the following:
drop_table :accounts, force: :cascade
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.