Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails 3 - How do I remove database tables that have been created?

I created 2 models and ran the migrations, attempted some work on each of them and now I would like to start over and approach them differently. I'm new to Rails and have never attempted to delete/remove database tables (apart from rolling them back right after I migrated them).

Thanks!

like image 561
teecraft Avatar asked Oct 12 '10 13:10

teecraft


1 Answers

To drop a table during a migration, you can rails g migration DropUsers

class DropUsers < ActiveRecord::Migration
  def up
    drop_table :users
  end

  def down
    # recreate table logic here
  end
end

You can also drop tables from the Rails console

ActiveRecord::Migration.drop_table(:users)

FYI If you want to remove scaffold-created code, rails destroy scaffold User

like image 52
scarver2 Avatar answered Oct 01 '22 16:10

scarver2