Rails remove old models with migrations

All in one solution.

Run the following commands:

rails destroy model ModelName
rails g migration DropTableModelName

The former will generate a new migration file which should looks like this:

class DropTableModelName < ActiveRecord::Migration
  def change
    drop_table :model_name
  end
end

Now run db:migrate and you're done.


If you'd like to completely get rid of of a model and its table do this:

rails destroy model Name

What about doing ruby script/destroy model? That should take care of the model and the migration.


The question is a bit stale now, but I just did:

rails destroy scaffold <ModelName> -p

The -p flag shows "pretend" output, which is good for seeing what will happen. Remove the '-p' flag and the results will match the output. This cleaned the entire collection of M-V-C files + testing + js files + the original migration, no problem.

I guess if you are one who likes to hand edit your migrations and include multiple steps in each, losing the original migration could break db:setup, so buyer beware. Keeping one action == one migration file should avoid this potential snafu.