# Advanced Migrations (Ruby on Rails) > Complex migrations, reversible migrations, data migrations, rollbacks, DB constraints vs validations, safe migrations - 20 interview questions - Mid-Level - [Interview Questions: Ruby on Rails](https://sharpskill.dev/en/technologies/ruby-on-rails/interview-questions.md) ## 1. What is the difference between the change and up/down methods in a Rails migration? **Answer** The change method is a simplified syntax introduced in Rails 3.1 that allows Rails to automatically infer the reverse operation. It works for most common operations like add_column or create_table. The up and down methods provide explicit control over apply and rollback operations, which is necessary when Rails cannot automatically infer the reverse, such as during data deletions or complex transformations. ## 2. How to make a migration reversible when Rails cannot automatically infer the reverse operation? **Answer** The reversible block allows explicitly defining up and down operations within a change method. This is particularly useful for operations like remove_column where Rails needs to know the column type and options to recreate it during rollback. The reversible block offers the flexibility of up/down while keeping the modern change syntax. ## 3. Which command allows rolling back multiple migrations in a single operation? **Answer** The rails db:rollback STEP=n command allows rolling back the last n executed migrations. For example, STEP=3 will roll back the last three migrations in reverse order of their execution. Without the STEP option, only the last migration is rolled back. This command is useful for quickly returning to a previous database state during development. ## 17 more questions available - Why avoid using ActiveRecord model references in data migrations? - What is the best practice for performing a data migration in production on a large table? Sign up for free: https://sharpskill.dev/en/login ## Other Ruby on Rails interview topics - [Ruby Basics](https://sharpskill.dev/en/technologies/ruby-on-rails/interview-questions/ruby-basics.md): 25 questions, Junior - [Ruby Object-Oriented Programming](https://sharpskill.dev/en/technologies/ruby-on-rails/interview-questions/ruby-oop.md): 20 questions, Junior - [Rails Fundamentals](https://sharpskill.dev/en/technologies/ruby-on-rails/interview-questions/rails-fundamentals.md): 18 questions, Junior - [Routing & Controllers](https://sharpskill.dev/en/technologies/ruby-on-rails/interview-questions/routing-controllers.md): 22 questions, Junior - [ActiveRecord Basics](https://sharpskill.dev/en/technologies/ruby-on-rails/interview-questions/active-record-basics.md): 25 questions, Junior - [Views & ERB Templates](https://sharpskill.dev/en/technologies/ruby-on-rails/interview-questions/views-erb-templates.md): 20 questions, Junior - [ActiveRecord Associations](https://sharpskill.dev/en/technologies/ruby-on-rails/interview-questions/active-record-associations.md): 24 questions, Mid-Level - [Advanced ActiveRecord Queries](https://sharpskill.dev/en/technologies/ruby-on-rails/interview-questions/active-record-queries.md): 28 questions, Mid-Level - [Rails Forms](https://sharpskill.dev/en/technologies/ruby-on-rails/interview-questions/rails-forms.md): 20 questions, Mid-Level - [Authentication & Authorization](https://sharpskill.dev/en/technologies/ruby-on-rails/interview-questions/authentication-authorization.md): 22 questions, Mid-Level - [Modern Asset Pipeline & Frontend](https://sharpskill.dev/en/technologies/ruby-on-rails/interview-questions/rails-asset-pipeline.md): 18 questions, Mid-Level - [Rails API Mode](https://sharpskill.dev/en/technologies/ruby-on-rails/interview-questions/rails-api-mode.md): 20 questions, Mid-Level - [Testing with RSpec](https://sharpskill.dev/en/technologies/ruby-on-rails/interview-questions/rails-testing-rspec.md): 24 questions, Mid-Level - [ActiveJob & Background Jobs](https://sharpskill.dev/en/technologies/ruby-on-rails/interview-questions/active-job-background-jobs.md): 20 questions, Mid-Level - [ActionCable & WebSockets](https://sharpskill.dev/en/technologies/ruby-on-rails/interview-questions/action-cable-websockets.md): 18 questions, Mid-Level - [ActionMailer](https://sharpskill.dev/en/technologies/ruby-on-rails/interview-questions/action-mailer.md): 18 questions, Mid-Level - [ActiveStorage](https://sharpskill.dev/en/technologies/ruby-on-rails/interview-questions/active-storage.md): 20 questions, Mid-Level - [Caching Strategies](https://sharpskill.dev/en/technologies/ruby-on-rails/interview-questions/caching-strategies.md): 20 questions, Mid-Level - [Rails Engines & Modular Apps](https://sharpskill.dev/en/technologies/ruby-on-rails/interview-questions/rails-engines-modular-apps.md): 18 questions, Senior - [Performance Optimization](https://sharpskill.dev/en/technologies/ruby-on-rails/interview-questions/performance-optimization.md): 26 questions, Senior - [Rails Design Patterns](https://sharpskill.dev/en/technologies/ruby-on-rails/interview-questions/rails-design-patterns.md): 22 questions, Senior - [Ruby Metaprogramming](https://sharpskill.dev/en/technologies/ruby-on-rails/interview-questions/ruby-metaprogramming.md): 20 questions, Senior - [Rails Security](https://sharpskill.dev/en/technologies/ruby-on-rails/interview-questions/rails-security.md): 22 questions, Senior - [GraphQL with Rails](https://sharpskill.dev/en/technologies/ruby-on-rails/interview-questions/graphql-rails.md): 20 questions, Senior - [Deployment & Production](https://sharpskill.dev/en/technologies/ruby-on-rails/interview-questions/rails-deployment-production.md): 20 questions, Senior - [Monitoring & Logging](https://sharpskill.dev/en/technologies/ruby-on-rails/interview-questions/monitoring-logging.md): 20 questions, Senior - [Rails Upgrade Strategies](https://sharpskill.dev/en/technologies/ruby-on-rails/interview-questions/rails-upgrade-strategies.md): 18 questions, Senior --- Source: SharpSkill (https://sharpskill.dev), tech interview preparation for your real stack. HTML version of this page: https://sharpskill.dev/en/technologies/ruby-on-rails/interview-questions/database-migrations-advanced