remove a table with migration

HI, guys, How to remove a table with migration, i saw a drop down method in migration created file , how can i use that ?

thank you.

In rails 3.0.9:

bundle exec rake db:rollback

In rails 3.0.9:

bundle exec rake db:rollback

Posted via http://www.ruby-forum.com/.

You received this message because you are subscribed to the Google Groups “Ruby on Rails: Talk” group.

To post to this group, send email to rubyonrails-talk@googlegroups.com.

To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.

For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

How to rollback specify table?

you have to create a migration like this :

rails g migration deleteTableTableName

  • open the file generated and in the ‘up’ method you should enter this :

def up

drop_table :table_name

end

  • close the file en run

rake db:migrate

And that’s all :slight_smile:

Good luck

I just use the self.down method of origin migration that creates the table to drop down the table but the command 'rake db:migrate' not works.

you have which version of rails ?

rails 3.0.9

I just use the self.down method of origin migration that creates the table to drop down the table

What do you mean by using the self.down method?

but the command 'rake db:migrate' not works.

Did you create a new migration with the drop table in as described by Lionel or are you just trying to rollback the previous migration?

Colin

Can i rollback the specify table ? for example, the 'db/migrate' directory have five migration files, i want to rollback one of them, if i use this command "rake db:migrate" that will rollback the lastly table.

bundle exec rake db:migrate:down VERSION=<long number here>

It really is not a good idea to do that, better to make a new migration. If you do rollback a migration that is not the last make sure you then delete the migration or if you run them from the start you will end up with the table back again. Also if any of the later migrations reference that table you will be in trouble if you run the migrations from scratch after deleting this one.

Colin

Good idea, if i need to rollback the migration that is not the lately one, it must be confused to me or rails. The good way is to create a new migration for rollbacking with the related time.