0

I want to delete a table in my rails app but i cannot use rollback, because i created this table a long time ago, and i have a LOT of other tables created since that one.

How is supposed to be named a drop table migration file and is there a way to genrate it with rails generate?

Kara
  • 6,115
  • 16
  • 50
  • 57
Syl
  • 3,719
  • 6
  • 35
  • 59

1 Answers1

9

Create one more migration to drop the table. The class should have the method

def self.up
  drop_table :table_name
end

Be careful as you will not be able to rollback to get all the data you will lose while dropping the table.

xpda
  • 15,585
  • 8
  • 51
  • 82
rtcoms
  • 783
  • 1
  • 8
  • 19
  • But how do i name it? remove_table_name.rb ? drop_table_name.rb? Will rails know how to update schema.rb? i always used "rails generate" to create the file, is it ok not to use it ? How do i get the timestamp for my new migration? – Syl Sep 07 '11 at 05:44
  • 2
    @Sylario - the migration's name doesn't have anything to do with its function. If you write the code properly it'll work regardless. – sscirrus Sep 07 '11 at 05:46
  • You can name your migration whatever you want (should follow the rules for naming of class) . – rtcoms Sep 07 '11 at 05:46
  • @sscirrus: But you do want timestamp in the migration's file name so the file name matters even if the class name doesn't. – mu is too short Sep 07 '11 at 05:53
  • @Sylario just do rails generate migration . It will generate migration with timestamp . Then write self.up and self.down methods accordingly .I hope this will help you. – rtcoms Sep 07 '11 at 05:57
  • @muIsTooShort - you're right that the timestamp is important. My understanding is that `rails g migration ...` adds your timestamp anyway, no? My point was with regard to functionality, but clearly a sensible naming convention is always a good thing. – sscirrus Sep 07 '11 at 06:45
  • @sscirrus: I'm not disagreeing with out, just trying to clarify a bit. – mu is too short Sep 07 '11 at 06:55