NameError: неинициализированная константа при запуске миграции с перекошенным именем

У меня есть этот файл миграции 20180226063342_add_bpm_to_songs.rb

class AddBpmToSongs < ActiveRecord::Migration[5.1]
  def change
    ..
  end
end

и это по моему inflections.rb

ActiveSupport::Inflector.inflections(:en) do |inflect|
  inflect.acronym 'BPM'
end

Когда я бегу rails db:migrate я получил

** Invoke db:migrate (first_time)
** Invoke environment (first_time)
** Execute environment
** Invoke db:load_config (first_time)
** Execute db:load_config
** Execute db:migrate
rails aborted!
NameError: uninitialized constant AddBPMToSongs
/Users/redacted/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/activesupport-5.1.1/lib/active_support/    inflector/methods.rb:269:in `const_get'
/Users/redacted/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/activesupport-5.1.1/lib/active_support/    inflector/methods.rb:269:in `block in constantize'
/Users/redacted/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/activesupport-5.1.1/lib/active_support/    inflector/methods.rb:267:in `each'
/Users/redacted/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/activesupport-5.1.1/lib/active_support/    inflector/methods.rb:267:in `inject'
/Users/redacted/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/activesupport-5.1.1/lib/active_support/    inflector/methods.rb:267:in `constantize'
/Users/redacted/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/activesupport-5.1.1/lib/active_support/    core_ext/string/inflections.rb:66:in `constantize'
/Users/redacted/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/activerecord-5.1.1/lib/active_record/    migration.rb:963:in `load_migration'
/Users/redacted/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/activerecord-5.1.1/lib/active_record/    migration.rb:958:in `migration'
/Users/redacted/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/activerecord-5.1.1/lib/active_record/    migration.rb:953:in `disable_ddl_transaction'
/Users/redacted/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/activerecord-5.1.1/lib/active_record/    migration.rb:1305:in `use_transaction?'
/Users/redacted/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/activerecord-5.1.1/lib/active_record/    migration.rb:1235:in `rescue in execute_migration_in_transaction'
/Users/redacted/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/activerecord-5.1.1/lib/active_record/    migration.rb:1224:in `execute_migration_in_transaction'
/Users/redacted/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/activerecord-5.1.1/lib/active_record/    migration.rb:1201:in `block in migrate_without_lock'
/Users/redacted/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/activerecord-5.1.1/lib/active_record/    migration.rb:1200:in `each'
/Users/redacted/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/activerecord-5.1.1/lib/active_record/    migration.rb:1200:in `migrate_without_lock'
/Users/redacted/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/activerecord-5.1.1/lib/active_record/    migration.rb:1148:in `block in migrate'
/Users/redacted/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/activerecord-5.1.1/lib/active_record/    migration.rb:1317:in `with_advisory_lock'
/Users/redacted/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/activerecord-5.1.1/lib/active_record/    migration.rb:1148:in `migrate'
/Users/redacted/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/activerecord-5.1.1/lib/active_record/    migration.rb:1007:in `up'
/Users/redacted/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/activerecord-5.1.1/lib/active_record/    migration.rb:985:in `migrate'
/Users/redacted/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/activerecord-5.1.1/lib/active_record/tasks/    database_tasks.rb:171:in `migrate'
/Users/redacted/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/activerecord-5.1.1/lib/active_record/railties/    databases.rake:58:in `block (2 levels) in <top (required)>'
/Users/redacted/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/rake-12.0.0/lib/rake/task.rb:250:in `block in     execute'
/Users/redacted/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/rake-12.0.0/lib/rake/task.rb:250:in `each'
/Users/redacted/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/rake-12.0.0/lib/rake/task.rb:250:in `execute'
/Users/redacted/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/rake-12.0.0/lib/rake/task.rb:194:in `block in     invoke_with_call_chain'
/Users/redacted/.rbenv/versions/2.4.1/lib/ruby/2.4.0/monitor.rb:214:in `mon_synchronize'
/Users/redacted/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/rake-12.0.0/lib/rake/task.rb:187:in     `invoke_with_call_chain'
/Users/redacted/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/rake-12.0.0/lib/rake/task.rb:180:in `invoke'
/Users/redacted/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/rake-12.0.0/lib/rake/application.rb:152:in     `invoke_task'
/Users/redacted/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/rake-12.0.0/lib/rake/application.rb:108:in     `block (2 levels) in top_level'
/Users/redacted/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/rake-12.0.0/lib/rake/application.rb:108:in     `each'
/Users/redacted/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/rake-12.0.0/lib/rake/application.rb:108:in     `block in top_level'
/Users/redacted/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/rake-12.0.0/lib/rake/application.rb:117:in     `run_with_threads'
/Users/redacted/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/rake-12.0.0/lib/rake/application.rb:102:in     `top_level'
/Users/redacted/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/railties-5.1.1/lib/rails/commands/rake/    rake_command.rb:21:in `block in perform'
/Users/redacted/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/rake-12.0.0/lib/rake/application.rb:178:in     `standard_exception_handling'
/Users/redacted/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/railties-5.1.1/lib/rails/commands/rake/    rake_command.rb:18:in `perform'
/Users/redacted/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/railties-5.1.1/lib/rails/command.rb:46:in     `invoke'
/Users/redacted/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/railties-5.1.1/lib/rails/commands.rb:16:in `<    top (required)>'
bin/rails:4:in `require'
bin/rails:4:in `<main>'
NameError: uninitialized constant AddBPMToSongs
/Users/redacted/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/activesupport-5.1.1/lib/active_support/    inflector/methods.rb:269:in `const_get'
/Users/redacted/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/activesupport-5.1.1/lib/active_support/    inflector/methods.rb:269:in `block in constantize'
/Users/redacted/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/activesupport-5.1.1/lib/active_support/    inflector/methods.rb:267:in `each'
/Users/redacted/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/activesupport-5.1.1/lib/active_support/    inflector/methods.rb:267:in `inject'
/Users/redacted/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/activesupport-5.1.1/lib/active_support/    inflector/methods.rb:267:in `constantize'
/Users/redacted/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/activesupport-5.1.1/lib/active_support/    core_ext/string/inflections.rb:66:in `constantize'
/Users/redacted/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/activerecord-5.1.1/lib/active_record/    migration.rb:963:in `load_migration'
/Users/redacted/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/activerecord-5.1.1/lib/active_record/    migration.rb:958:in `migration'
/Users/redacted/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/activerecord-5.1.1/lib/active_record/    migration.rb:953:in `disable_ddl_transaction'
/Users/redacted/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/activerecord-5.1.1/lib/active_record/    migration.rb:1305:in `use_transaction?'
/Users/redacted/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/activerecord-5.1.1/lib/active_record/    migration.rb:1297:in `ddl_transaction'
/Users/redacted/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/activerecord-5.1.1/lib/active_record/    migration.rb:1229:in `execute_migration_in_transaction'
/Users/redacted/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/activerecord-5.1.1/lib/active_record/    migration.rb:1201:in `block in migrate_without_lock'
/Users/redacted/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/activerecord-5.1.1/lib/active_record/    migration.rb:1200:in `each'
/Users/redacted/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/activerecord-5.1.1/lib/active_record/    migration.rb:1200:in `migrate_without_lock'
/Users/redacted/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/activerecord-5.1.1/lib/active_record/    migration.rb:1148:in `block in migrate'
/Users/redacted/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/activerecord-5.1.1/lib/active_record/    migration.rb:1317:in `with_advisory_lock'
/Users/redacted/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/activerecord-5.1.1/lib/active_record/    migration.rb:1148:in `migrate'
/Users/redacted/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/activerecord-5.1.1/lib/active_record/    migration.rb:1007:in `up'
/Users/redacted/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/activerecord-5.1.1/lib/active_record/    migration.rb:985:in `migrate'
/Users/redacted/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/activerecord-5.1.1/lib/active_record/tasks/    database_tasks.rb:171:in `migrate'
/Users/redacted/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/activerecord-5.1.1/lib/active_record/railties/    databases.rake:58:in `block (2 levels) in <top (required)>'
/Users/redacted/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/rake-12.0.0/lib/rake/task.rb:250:in `block in     execute'
/Users/redacted/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/rake-12.0.0/lib/rake/task.rb:250:in `each'
/Users/redacted/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/rake-12.0.0/lib/rake/task.rb:250:in `execute'
/Users/redacted/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/rake-12.0.0/lib/rake/task.rb:194:in `block in     invoke_with_call_chain'
/Users/redacted/.rbenv/versions/2.4.1/lib/ruby/2.4.0/monitor.rb:214:in `mon_synchronize'
/Users/redacted/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/rake-12.0.0/lib/rake/task.rb:187:in     `invoke_with_call_chain'
/Users/redacted/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/rake-12.0.0/lib/rake/task.rb:180:in `invoke'
/Users/redacted/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/rake-12.0.0/lib/rake/application.rb:152:in     `invoke_task'
/Users/redacted/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/rake-12.0.0/lib/rake/application.rb:108:in     `block (2 levels) in top_level'
/Users/redacted/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/rake-12.0.0/lib/rake/application.rb:108:in     `each'
/Users/redacted/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/rake-12.0.0/lib/rake/application.rb:108:in     `block in top_level'
/Users/redacted/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/rake-12.0.0/lib/rake/application.rb:117:in     `run_with_threads'
/Users/redacted/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/rake-12.0.0/lib/rake/application.rb:102:in     `top_level'
/Users/redacted/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/railties-5.1.1/lib/rails/commands/rake/    rake_command.rb:21:in `block in perform'
/Users/redacted/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/rake-12.0.0/lib/rake/application.rb:178:in     `standard_exception_handling'
/Users/redacted/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/railties-5.1.1/lib/rails/commands/rake/    rake_command.rb:18:in `perform'
/Users/redacted/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/railties-5.1.1/lib/rails/command.rb:46:in     `invoke'
/Users/redacted/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/railties-5.1.1/lib/rails/commands.rb:16:in `<    top (required)>'
bin/rails:4:in `require'
bin/rails:4:in `<main>'
Tasks: TOP => db:migrate

Я знаю, что это связано с BPM перегиб, потому что, если я удаляю его, то миграция проходит успешно. Тем не менее, я действительно хочу сохранить этот перегиб.

Кто-нибудь знает, почему файл миграции неправильно изменяется и что я могу с этим сделать?

1 ответ

Прежде всего вам нужно заполнить среду Rails, поэтому, пожалуйста, не забудьте установить RAILS_ENV=production перед командами CLI.

Эти правила перегиба (акроним) поддерживаются, но не включены по умолчанию:

ActiveSupport::Inflector.inflections(:en) do |inflect|
   inflect.acronym 'BPM'
end

Аббревиатуры, которые передаются для множественного числа, больше не будут распознаваться, так как аббревиатура не будет появляться в качестве разделенной единицы в результате множественного результата. Чтобы обойти это, вы также должны указать множественную форму как аббревиатуру:

acronym 'BPM'
camelize(pluralize('bpm')) # => 'bpm'
Другие вопросы по тегам