2

I would like to arbitrarily drop all tables in my Rails app via a Rake task.

This is for testing/staging purposes, and rolling back migrations doesn't seem appropriate/necessary here.

I've got to:

ActiveRecord::Base.connection.tables.each do |t|
  puts "=== Deleting: #{t.to_s}"
  drop_table t
end

But of course drop_table is undefined in this context. How should I call it?

4

2 に答える 2

4

Okay, I found an answer here: http://problemateek.blogspot.co.uk/2012/07/drop-table-from-rails-console.html

The call just needs to be scoped under ActiveRecord::Migration like so:

ActiveRecord::Migration.drop_table t
于 2013-05-15T16:39:48.717 に答える