Billy Logan Billy Logan - 2 years ago 109
Ruby Question

How to run migration generation from console?

I want to try to generate migration inside rails console.

This file is responsible for migration creation (particularly create_migrate_file method):


enter image description here

But, for some reason, in my console I can't call ActiveRecord::Generators::MigrationGenerator class.

enter image description here

NameError: uninitialized constant ActiveRecord::Generators::MigrationGenerator

What can I do in this case?

Answer Source

You need to first require rails/generators and then the file where ActiveRecord::Generators::MigrationGenerator is defined.

require 'rails/generators'
require 'rails/generators/active_record/migration/migration_generator'

# => ActiveRecord::Generators::MigrationGenerator
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download