Friday, August 12, 2016

How to drop a table using Rails database migration in the console?

In Rails 5, you can go to the console and do this:

ActiveRecord::Migration.drop_table(:products)
- drop_table(:products)
   (29.8ms)  DROP TABLE "products"
   -> 0.0303s
=> []
If you list the tables, you will see that products table is no longer in the database:

>> ActiveRecord::Base.connection.data_sources
=> ["schema_migrations", "ar_internal_metadata"]

No comments:

Post a Comment