HOWTO fix ActiveRecord migration NoMethodError in Rails 5.2

Ruby on Rails 5.2 changed the method signature for ActiveRecord::Migrator.migrate().

The old signature was this:

def migrate(migrations_paths, target_version = nil, &block)

The new signature is this:

def migrate(target_version = nil, &block)

Suppose you had some Rails 5.1 code like so:

ActiveRecord::Migrator.migrate(
  ActiveRecord::Tasks::DatabaseTasks.migrations_paths,
  version,
)

If you ran it in Rails 5.2, you would get this error:

NoMethodError: undefined method `migrate' for ActiveRecord::Migrator:Class

In Rails 5.2, you would write:

ActiveRecord::MigrationContext.new( ActiveRecord::Tasks::DatabaseTasks.migrations_paths ).migrate( version )

Leave a comment

Your email address will not be published. Required fields are marked *