gpt4 book ai didi

ruby-on-rails - rake 中止未初始化的常量 "Computers"

转载 作者:行者123 更新时间:2023-12-04 09:27:10 24 4
gpt4 key购买 nike

我的迁移有一个非常烦人的问题。

首先是错误消息:

bundle exec rake db:migrate --trace
(in /home/myhomefolder/msdnaa)
** Invoke db:migrate (first_time)
** Invoke environment (first_time)
** Execute environment
** Execute db:migrate
rake aborted!
An error has occurred, all later migrations canceled:

uninitialized constant Computers

现在我假设我们的一位管理员所做的更新是每次都会发生这种情况的原因。即使根本没有迁移!

我所做的(除了在 Stack Overflow 上搜索解决方案之外)是为“计算机”搜索每个文件。
当然有一些文件包含这个词,我检查了它们是否有语法错误和常见的东西,比如缺少“:”。
然后我向一位同事寻求帮助(他在 ruby​​ 方面比我更熟练),但他没有任何线索,一切看起来都正确。

我使用的是稍微旧的 Ruby (1.8.7) 和 Rails (3.0.9) 版本,但我无权在我们的服务器上进行更新,所以我必须处理它。
是的,我要求管理员更新 1.9.x 和 3.1.x,但这不是问题,因为它上周运行良好。
所以这是它应该工作的那些错误之一,但它没有,我敢打赌解决方案就像喝水一样简单,但我没有看到它!

有什么建议?

编辑:这是--trace:
/var/lib/gems/1.8/gems/activesupport-3.0.9/lib/active_support/inflector/meth               ods.rb:113:in `constantize'
/var/lib/gems/1.8/gems/activesupport-3.0.9/lib/active_support/inflector/meth ods.rb:112:in `each'
/var/lib/gems/1.8/gems/activesupport-3.0.9/lib/active_support/inflector/meth ods.rb:112:in `constantize'
/var/lib/gems/1.8/gems/activesupport-3.0.9/lib/active_support/core_ext/strin g/inflections.rb:43:in `constantize'
/var/lib/gems/1.8/gems/activerecord-3.0.9/lib/active_record/migration.rb:407 :in `load_migration'
/var/lib/gems/1.8/gems/activerecord-3.0.9/lib/active_record/migration.rb:402 :in `migration'
/var/lib/gems/1.8/gems/activerecord-3.0.9/lib/active_record/migration.rb:397 :in `migrate'
/var/lib/gems/1.8/gems/activerecord-3.0.9/lib/active_record/migration.rb:539 :in `migrate'
/var/lib/gems/1.8/gems/activerecord-3.0.9/lib/active_record/migration.rb:615 :in `call'
/var/lib/gems/1.8/gems/activerecord-3.0.9/lib/active_record/migration.rb:615 :in `ddl_transaction'
/var/lib/gems/1.8/gems/activerecord-3.0.9/lib/active_record/migration.rb:538 :in `migrate'
/var/lib/gems/1.8/gems/activerecord-3.0.9/lib/active_record/migration.rb:525 :in `each'
/var/lib/gems/1.8/gems/activerecord-3.0.9/lib/active_record/migration.rb:525 :in `migrate'
/var/lib/gems/1.8/gems/activerecord-3.0.9/lib/active_record/migration.rb:435 :in `up'
/var/lib/gems/1.8/gems/activerecord-3.0.9/lib/active_record/migration.rb:417 :in `migrate'
/var/lib/gems/1.8/gems/activerecord-3.0.9/lib/active_record/railties/databas es.rake:142
/var/lib/gems/1.8/gems/rake-0.9.2/lib/rake/task.rb:205:in `call'
/var/lib/gems/1.8/gems/rake-0.9.2/lib/rake/task.rb:205:in `execute'
/var/lib/gems/1.8/gems/rake-0.9.2/lib/rake/task.rb:200:in `each'
/var/lib/gems/1.8/gems/rake-0.9.2/lib/rake/task.rb:200:in `execute'
/var/lib/gems/1.8/gems/rake-0.9.2/lib/rake/task.rb:158:in `invoke_with_call_ chain'
/usr/lib/ruby/1.8/monitor.rb:242:in `synchronize'
/var/lib/gems/1.8/gems/rake-0.9.2/lib/rake/task.rb:151:in `invoke_with_call_ chain'
/var/lib/gems/1.8/gems/rake-0.9.2/lib/rake/task.rb:144:in `invoke'
/var/lib/gems/1.8/gems/rake-0.9.2/lib/rake/application.rb:112:in `invoke_tas k'
/var/lib/gems/1.8/gems/rake-0.9.2/lib/rake/application.rb:90:in `top_level'
/var/lib/gems/1.8/gems/rake-0.9.2/lib/rake/application.rb:90:in `each'
/var/lib/gems/1.8/gems/rake-0.9.2/lib/rake/application.rb:90:in `top_level'
/var/lib/gems/1.8/gems/rake-0.9.2/lib/rake/application.rb:129:in `standard_e xception_handling'
/var/lib/gems/1.8/gems/rake-0.9.2/lib/rake/application.rb:84:in `top_level'
/var/lib/gems/1.8/gems/rake-0.9.2/lib/rake/application.rb:62:in `run'
/var/lib/gems/1.8/gems/rake-0.9.2/lib/rake/application.rb:129:in `standard_e xception_handling'
/var/lib/gems/1.8/gems/rake-0.9.2/lib/rake/application.rb:59:in `run'
/var/lib/gems/1.8/gems/rake-0.9.2/bin/rake:32
/var/lib/gems/1.8/bin/rake:19:in `load'
/var/lib/gems/1.8/bin/rake:19
Tasks: TOP => db:migrate

最佳答案

我的猜测是您刚刚添加了一个名为 20120221123456_computers.rb 之类的迁移,在其中,您有类似...

class SomeNameThatsNotComputers < ActiveRecord::Migration
...

当 Rails 执行迁移时,它希望执行定义类的文件,然后实例化类,并在该类实例上调用 #up 或 #down。 Rails 如何知道要实例化哪个类?它应该与数字前缀和下划线后面的文件名部分相对应,因此对于像20120221123456_computers.rb这样的文件名,类名必须是Computers。

关于ruby-on-rails - rake 中止未初始化的常量 "Computers",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9375217/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com