Removing a model in rails (reverse of "rails g model Title...") Removing a model in rails (reverse of "rails g model Title...") ruby ruby

Removing a model in rails (reverse of "rails g model Title...")


When you generate a model, it creates a database migration. If you run 'destroy' on that model, it will delete the migration file, but not the database table. So before run

bundle exec rails db:rollbackrails destroy model <model_name>

For rails versions before 5.0 and higher use rake instead of rails

bundle exec rake db:rollback   rails destroy model <model_name>


Try this

rails destroy model Rating

It will remove model, migration, tests and fixtures


For future questioners: If you can't drop the tables from the console, try to create a migration that drops the tables for you. You should create a migration and then in the file note tables you want dropped like this:

class DropTables < ActiveRecord::Migration  def up    drop_table :table_you_dont_want  end  def down    raise ActiveRecord::IrreversibleMigration  endend