0

在使用 Capistrano 部署后,让我的应用程序成功运行 rake db:migrate 时遇到了真正的问题。该应用程序在开发模式下运行良好,但是当我尝试部署到我的 Ubuntu 12.04 服务器时,我得到以下输出:

/var/mdnapp/current$ bundle exec rake db:migrate --trace
** Invoke db:migrate (first_time)
** Invoke environment (first_time)
** Execute environment
** Invoke db:load_config (first_time)
** Invoke rails_env (first_time)
** Execute rails_env
** Execute db:load_config
** Execute db:migrate
rake aborted!
An error has occurred, all later migrations canceled:

wrong constant name 0Bak
/var/mdnapp/shared/bundle/ruby/1.9.1/gems/activesupport-3.2.2/lib/active_support/inflector/methods.rb:229:in `const_defined?'
/var/mdnapp/shared/bundle/ruby/1.9.1/gems/activesupport-3.2.2/lib/active_support/inflector/methods.rb:229:in `block in constantize'
/var/mdnapp/shared/bundle/ruby/1.9.1/gems/activesupport-3.2.2/lib/active_support/inflector/methods.rb:228:in `each'
/var/mdnapp/shared/bundle/ruby/1.9.1/gems/activesupport-3.2.2/lib/active_support/inflector/methods.rb:228:in `constantize'
/var/mdnapp/shared/bundle/ruby/1.9.1/gems/activesupport-3.2.2/lib/active_support/core_ext/string/inflections.rb:54:in `constantize'
/var/mdnapp/shared/bundle/ruby/1.9.1/gems/activerecord-3.2.2/lib/active_record/migration.rb:522:in `load_migration'
/var/mdnapp/shared/bundle/ruby/1.9.1/gems/activerecord-3.2.2/lib/active_record/migration.rb:517:in `migration'
/var/mdnapp/shared/bundle/ruby/1.9.1/gems/activerecord-3.2.2/lib/active_record/migration.rb:512:in `migrate'
/var/mdnapp/shared/bundle/ruby/1.9.1/gems/activerecord-3.2.2/lib/active_record/migration.rb:704:in `block (2 levels) in migrate'
/var/mdnapp/shared/bundle/ruby/1.9.1/gems/activerecord-3.2.2/lib/active_record/migration.rb:761:in `call'
/var/mdnapp/shared/bundle/ruby/1.9.1/gems/activerecord-3.2.2/lib/active_record/migration.rb:761:in `ddl_transaction'
/var/mdnapp/shared/bundle/ruby/1.9.1/gems/activerecord-3.2.2/lib/active_record/migration.rb:703:in `block in migrate'
/var/mdnapp/shared/bundle/ruby/1.9.1/gems/activerecord-3.2.2/lib/active_record/migration.rb:684:in `each'
/var/mdnapp/shared/bundle/ruby/1.9.1/gems/activerecord-3.2.2/lib/active_record/migration.rb:684:in `migrate'
/var/mdnapp/shared/bundle/ruby/1.9.1/gems/activerecord-3.2.2/lib/active_record/migration.rb:554:in `up'
/var/mdnapp/shared/bundle/ruby/1.9.1/gems/activerecord-3.2.2/lib/active_record/migration.rb:535:in `migrate'
/var/mdnapp/shared/bundle/ruby/1.9.1/gems/activerecord-3.2.2/lib/active_record/railties/databases.rake:153:in `block (2 levels) in <top (required)>'
/var/mdnapp/shared/bundle/ruby/1.9.1/gems/rake-10.0.3/lib/rake/task.rb:228:in `call'
/var/mdnapp/shared/bundle/ruby/1.9.1/gems/rake-10.0.3/lib/rake/task.rb:228:in `block in execute'
/var/mdnapp/shared/bundle/ruby/1.9.1/gems/rake-10.0.3/lib/rake/task.rb:223:in `each'
/var/mdnapp/shared/bundle/ruby/1.9.1/gems/rake-10.0.3/lib/rake/task.rb:223:in `execute'
/var/mdnapp/shared/bundle/ruby/1.9.1/gems/rake-10.0.3/lib/rake/task.rb:166:in `block in invoke_with_call_chain'
/usr/local/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize'
/var/mdnapp/shared/bundle/ruby/1.9.1/gems/rake-10.0.3/lib/rake/task.rb:159:in `invoke_with_call_chain'
/var/mdnapp/shared/bundle/ruby/1.9.1/gems/rake-10.0.3/lib/rake/task.rb:152:in `invoke'
/var/mdnapp/shared/bundle/ruby/1.9.1/gems/rake-10.0.3/lib/rake/application.rb:143:in `invoke_task'
/var/mdnapp/shared/bundle/ruby/1.9.1/gems/rake-10.0.3/lib/rake/application.rb:101:in `block (2 levels) in top_level'
/var/mdnapp/shared/bundle/ruby/1.9.1/gems/rake-10.0.3/lib/rake/application.rb:101:in `each'
/var/mdnapp/shared/bundle/ruby/1.9.1/gems/rake-10.0.3/lib/rake/application.rb:101:in `block in top_level'
/var/mdnapp/shared/bundle/ruby/1.9.1/gems/rake-10.0.3/lib/rake/application.rb:110:in `run_with_threads'
/var/mdnapp/shared/bundle/ruby/1.9.1/gems/rake-10.0.3/lib/rake/application.rb:95:in `top_level'
/var/mdnapp/shared/bundle/ruby/1.9.1/gems/rake-10.0.3/lib/rake/application.rb:73:in `block in run'
/var/mdnapp/shared/bundle/ruby/1.9.1/gems/rake-10.0.3/lib/rake/application.rb:160:in `standard_exception_handling'
/var/mdnapp/shared/bundle/ruby/1.9.1/gems/rake-10.0.3/lib/rake/application.rb:70:in `run'
/var/mdnapp/shared/bundle/ruby/1.9.1/gems/rake-10.0.3/bin/rake:33:in `<top (required)>'
/var/mdnapp/shared/bundle/ruby/1.9.1/bin/rake:23:in `load'
/var/mdnapp/shared/bundle/ruby/1.9.1/bin/rake:23:in `<main>'
Tasks: TOP => db:migrate

我正在运行:rails 3.2.2 mysql2 0.3.11 ruby​​ 1.9.3

在寻找这方面的答案时,我遇到了一些关于模型不正确的 CamelCase 的评论。我检查了我的,它们在文件名中都是小写的(例如 user.rb),但在类名中它们是 CamelCase。变形器的文档描述了 NameError 并将其定义为:“当名称不在 CamelCase 中或常量未知时引发 NameError。”

http://www.rubydoc.info/github/rails/rails/master/ActiveSupport/Inflector:constantize

但我不确定我的代码中还有哪些地方可以查找可能的 CamelCase 错误。我无法弄清楚这是怎么回事。任何帮助将不胜感激。

4

1 回答 1

2

好的。我发现了问题。我的 db>migrate 文件夹中有一个名为 backup_migrations 的文件夹。我一定是在某个时候创建​​了它来存储一些我想在修改原件时备份的迁移。此文件夹中的这些迁移之一以原始名称命名,但扩展名为“.0.bak”。无论如何,我删除了 backup_migrations 文件夹,一切都按预期工作。

因此,对于正在为类似“rake aborted!错误的常量名称”而苦苦挣扎的其他人来说,可能需要检查您的迁移文件是否存在命名或驼峰式错误。我希望这对其他人有帮助,花费了我很多时间。事后看来,答案总是显而易见的。

于 2013-01-27T14:15:50.943 回答