how to reset migrations rails

To reset migrations in Rails, follow these steps:

  1. Open a terminal window.

  2. Navigate to your Rails application's root directory using the cd command.

cd path/to/your/rails/app
  1. Run the following command to drop the existing database:
rails db:drop
  1. Create a new database:
rails db:create
  1. Run the following command to generate a new set of migrations:
rails generate migration ResetMigrations
  1. Open the newly created migration file in the db/migrate directory. This file will be named something like timestamp_reset_migrations.rb.

  2. Inside the migration file, use the drop_table method to drop each table in the database. For example:

class ResetMigrations < ActiveRecord::Migration[6.0]
  def change
    drop_table :table1
    drop_table :table2
    # Drop all other tables
  end
end

Replace table1, table2, etc., with the names of your actual tables.

  1. Save the changes to the migration file.

  2. Run the migrations:

rails db:migrate
  1. If your application uses a seeds.rb file to populate the database with initial data, run:
rails db:seed

Now, your database should be reset with the new migrations applied.

Note: Make sure to review and update the ResetMigrations migration file to suit your specific database schema before running the migrations.