Lee7355512727
Lee7355512727

Reputation: 69

Rails 3: How to write a migration to remove a model and it's tables

I have an "Sqimage" (subquestion-image) model in my project. But later I created a "Qimage" model to replace "Sqimage"so I want to get rid of the old "Sqimage" model and the "Sqimage" table. I do not want to use

rake db:rollback 

because if someone else uses the project later, he needs to run "rake db:rollbakck" manually again. All I want to do is to create a new migration so that someone later can just run "rake db:migrate" to get everything done. I searched the Rails Guide and found there was no command line instruction to create such a migration. So does anybody know how to write such a migration to delete the model and the table? What should the name of the class be, and what method should I use? Here is the migration for creating the "Sqimage" model:

class CreateSqimages < ActiveRecord::Migration
  def change
    create_table :sqimages do |t|
      t.belongs_to :subquestion
      t.string :directory

      t.timestamps
    end
    add_index :sqimages, :subquestion_id
  end
end

Upvotes: 0

Views: 144

Answers (1)

Alex D
Alex D

Reputation: 30445

Just generate a new migration which uses drop_table to remove the unneeded table. You can manually delete the model .rb file.

Upvotes: 1

Related Questions