[英]How to run migration generation from console?
I want to try to generate migration inside rails console.我想尝试在 rails 控制台内生成迁移。
This file is responsible for migration creation (particularly create_migrate_file method):这个文件负责迁移创建(特别是create_migrate_file方法):
rails/generators/active_record/migration/migration_generator.rb rails/generators/active_record/migration/migration_generator.rb
But, for some reason, in my console I can't call ActiveRecord::Generators::MigrationGenerator class.但是,出于某种原因,在我的控制台中,我无法调用ActiveRecord::Generators::MigrationGenerator类。
NameError: uninitialized constant ActiveRecord::Generators::MigrationGenerator
What can I do in this case?在这种情况下我能做什么?
You need to first require rails/generators
and then the file where ActiveRecord::Generators::MigrationGenerator
is defined.您需要首先需要
rails/generators
,然后是定义ActiveRecord::Generators::MigrationGenerator
的文件。
require 'rails/generators'
require 'rails/generators/active_record/migration/migration_generator'
ActiveRecord::Generators::MigrationGenerator
# => ActiveRecord::Generators::MigrationGenerator
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.