Rake:当我尝试迁移时说表不存在......不,它不存在,这就是我尝试迁移的原因?

发布于 2024-12-02 10:32:43 字数 6799 浏览 0 评论 0原文

命令和跟踪:

% rake db:migrate RAILS_ENV=test --trace
(in /Users/lprestonsegoiii/Work/GravityLabs/TinderBox)
** Invoke db:migrate (first_time)
** Invoke environment (first_time)
** Execute environment
rake aborted!
Mysql::Error: Table 'project.medias' doesn't exist: SHOW FIELDS FROM `medias`
/Library/Ruby/Gems/1.8/gems/activerecord-2.3.8/lib/active_record/connection_adapters/abstract_adapter.rb:221:in `log'
/Library/Ruby/Gems/1.8/gems/activerecord-2.3.8/lib/active_record/connection_adapters/mysql_adapter.rb:323:in `execute'
/Library/Ruby/Gems/1.8/gems/activerecord-2.3.8/lib/active_record/connection_adapters/mysql_adapter.rb:470:in `columns'
/Library/Ruby/Gems/1.8/gems/activerecord-2.3.8/lib/active_record/base.rb:1301:in `columns'
/Library/Ruby/Gems/1.8/gems/activerecord-2.3.8/lib/active_record/base.rb:1314:in `column_names'
/Library/Ruby/Gems/1.8/gems/searchlogic-2.5.6/lib/searchlogic/named_scopes/ordering.rb:33:in `ordering_condition_details'
/Library/Ruby/Gems/1.8/gems/searchlogic-2.5.6/lib/searchlogic/named_scopes/ordering.rb:25:in `create_condition'
/Library/Ruby/Gems/1.8/gems/searchlogic-2.5.6/lib/searchlogic/named_scopes/or_conditions.rb:28:in `create_condition'
/Library/Ruby/Gems/1.8/gems/searchlogic-2.5.6/lib/searchlogic/named_scopes/column_conditions.rb:63:in `respond_to?'
/Library/Ruby/Gems/1.8/gems/activerecord-2.3.8/lib/active_record/base.rb:1511:in `respond_to?'
/Library/Ruby/Gems/1.8/gems/paperclip-2.4.0/lib/paperclip.rb:402:in `attachment_definitions'
/Library/Ruby/Gems/1.8/gems/paperclip-2.4.0/lib/paperclip.rb:283:in `has_attached_file'
/project/app/models/media.rb:23
/Library/Ruby/Gems/1.8/gems/activesupport-2.3.8/lib/active_support/dependencies.rb:158:in `require'
/Library/Ruby/Gems/1.8/gems/activesupport-2.3.8/lib/active_support/dependencies.rb:158:in `require'
/Library/Ruby/Gems/1.8/gems/activesupport-2.3.8/lib/active_support/dependencies.rb:265:in `require_or_load'
/Library/Ruby/Gems/1.8/gems/activesupport-2.3.8/lib/active_support/dependencies.rb:425:in `load_missing_constant'
/Library/Ruby/Gems/1.8/gems/activesupport-2.3.8/lib/active_support/dependencies.rb:80:in `const_missing'
/Library/Ruby/Gems/1.8/gems/activesupport-2.3.8/lib/active_support/dependencies.rb:92:in `const_missing'
project/test/factories/general.rb:87  #This is where Media is referenced... but it should have errored about any of the other 10 Models that don't have tables above where this one is used in this file....
/Library/Ruby/Gems/1.8/gems/activesupport-2.3.8/lib/active_support/dependencies.rb:147:in `load_without_new_constant_marking'
/Library/Ruby/Gems/1.8/gems/activesupport-2.3.8/lib/active_support/dependencies.rb:147:in `load'
/Library/Ruby/Gems/1.8/gems/factory_girl-2.0.5/lib/factory_girl/find_definitions.rb:20:in `find_definitions'
/Library/Ruby/Gems/1.8/gems/factory_girl-2.0.5/lib/factory_girl/find_definitions.rb:19:in `each'
/Library/Ruby/Gems/1.8/gems/factory_girl-2.0.5/lib/factory_girl/find_definitions.rb:19:in `find_definitions'
/Library/Ruby/Gems/1.8/gems/factory_girl-2.0.5/lib/factory_girl/find_definitions.rb:15:in `each'
/Library/Ruby/Gems/1.8/gems/factory_girl-2.0.5/lib/factory_girl/find_definitions.rb:15:in `find_definitions'
/Library/Ruby/Gems/1.8/gems/factory_girl-2.0.5/lib/factory_girl/rails2.rb:6
/Library/Ruby/Gems/1.8/gems/rails-2.3.8/lib/initializer.rb:614:in `call'
/Library/Ruby/Gems/1.8/gems/rails-2.3.8/lib/initializer.rb:614:in `after_initialize'
/Library/Ruby/Gems/1.8/gems/rails-2.3.8/lib/initializer.rb:613:in `each'
/Library/Ruby/Gems/1.8/gems/rails-2.3.8/lib/initializer.rb:613:in `after_initialize'
/Library/Ruby/Gems/1.8/gems/rails-2.3.8/lib/initializer.rb:179:in `process'
/Library/Ruby/Gems/1.8/gems/rails-2.3.8/lib/initializer.rb:113:in `send'
/Library/Ruby/Gems/1.8/gems/rails-2.3.8/lib/initializer.rb:113:in `run'
/project/config/environment.rb:17   #why does it jump into the env? this is irrelevant to raking.
/Library/Ruby/Gems/1.8/gems/activesupport-2.3.8/lib/active_support/dependencies.rb:156:in `require'
/Library/Ruby/Gems/1.8/gems/activesupport-2.3.8/lib/active_support/dependencies.rb:156:in `require'
/Library/Ruby/Gems/1.8/gems/activesupport-2.3.8/lib/active_support/dependencies.rb:521:in `new_constants_in'
/Library/Ruby/Gems/1.8/gems/activesupport-2.3.8/lib/active_support/dependencies.rb:156:in `require'
/Library/Ruby/Gems/1.8/gems/rails-2.3.8/lib/tasks/misc.rake:4
/Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:636:in `call'
/Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:636:in `execute'
/Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:631:in `each'
/Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:631:in `execute'
/Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:597:in `invoke_with_call_chain'
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/monitor.rb:242:in `synchronize'
/Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:590:in `invoke_with_call_chain'
/Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:607:in `invoke_prerequisites'
/Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:604:in `each'
/Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:604:in `invoke_prerequisites'
/Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:596:in `invoke_with_call_chain'
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/monitor.rb:242:in `synchronize'
/Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:590:in `invoke_with_call_chain'
/Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:583:in `invoke'
/Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:2051:in `invoke_task'
/Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:2029:in `top_level'
/Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:2029:in `each'
/Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:2029:in `top_level'
/Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:2068:in `standard_exception_handling'
/Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:2023:in `top_level'
/Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:2001:in `run'
/Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:2068:in `standard_exception_handling'
/Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:1998:in `run'
/Library/Ruby/Gems/1.8/gems/rake-0.8.7/bin/rake:31
/usr/bin//rake:19:in `load'
/usr/bin//rake:19

编辑: 第一个迁移文件: http://pastebin.com/49aJe2wv 它出错的表甚至还不存在。

测试数据库中没有表。

EDIT2:堆栈跟踪的详细信息 工厂/一般:87

Factory.define :media, :class => Media do |m| #line 87 <----
  m.name "Alice is in an asian wonderland"
  m.document_file_name "alice_test_image.jpeg"
  m.document_content_type "image/jpeg"
  m.document_file_size "155548"
...
end

编辑3: 媒体.rb http://pastebin.com/rZpdBTyq

Command and trace:

% rake db:migrate RAILS_ENV=test --trace
(in /Users/lprestonsegoiii/Work/GravityLabs/TinderBox)
** Invoke db:migrate (first_time)
** Invoke environment (first_time)
** Execute environment
rake aborted!
Mysql::Error: Table 'project.medias' doesn't exist: SHOW FIELDS FROM `medias`
/Library/Ruby/Gems/1.8/gems/activerecord-2.3.8/lib/active_record/connection_adapters/abstract_adapter.rb:221:in `log'
/Library/Ruby/Gems/1.8/gems/activerecord-2.3.8/lib/active_record/connection_adapters/mysql_adapter.rb:323:in `execute'
/Library/Ruby/Gems/1.8/gems/activerecord-2.3.8/lib/active_record/connection_adapters/mysql_adapter.rb:470:in `columns'
/Library/Ruby/Gems/1.8/gems/activerecord-2.3.8/lib/active_record/base.rb:1301:in `columns'
/Library/Ruby/Gems/1.8/gems/activerecord-2.3.8/lib/active_record/base.rb:1314:in `column_names'
/Library/Ruby/Gems/1.8/gems/searchlogic-2.5.6/lib/searchlogic/named_scopes/ordering.rb:33:in `ordering_condition_details'
/Library/Ruby/Gems/1.8/gems/searchlogic-2.5.6/lib/searchlogic/named_scopes/ordering.rb:25:in `create_condition'
/Library/Ruby/Gems/1.8/gems/searchlogic-2.5.6/lib/searchlogic/named_scopes/or_conditions.rb:28:in `create_condition'
/Library/Ruby/Gems/1.8/gems/searchlogic-2.5.6/lib/searchlogic/named_scopes/column_conditions.rb:63:in `respond_to?'
/Library/Ruby/Gems/1.8/gems/activerecord-2.3.8/lib/active_record/base.rb:1511:in `respond_to?'
/Library/Ruby/Gems/1.8/gems/paperclip-2.4.0/lib/paperclip.rb:402:in `attachment_definitions'
/Library/Ruby/Gems/1.8/gems/paperclip-2.4.0/lib/paperclip.rb:283:in `has_attached_file'
/project/app/models/media.rb:23
/Library/Ruby/Gems/1.8/gems/activesupport-2.3.8/lib/active_support/dependencies.rb:158:in `require'
/Library/Ruby/Gems/1.8/gems/activesupport-2.3.8/lib/active_support/dependencies.rb:158:in `require'
/Library/Ruby/Gems/1.8/gems/activesupport-2.3.8/lib/active_support/dependencies.rb:265:in `require_or_load'
/Library/Ruby/Gems/1.8/gems/activesupport-2.3.8/lib/active_support/dependencies.rb:425:in `load_missing_constant'
/Library/Ruby/Gems/1.8/gems/activesupport-2.3.8/lib/active_support/dependencies.rb:80:in `const_missing'
/Library/Ruby/Gems/1.8/gems/activesupport-2.3.8/lib/active_support/dependencies.rb:92:in `const_missing'
project/test/factories/general.rb:87  #This is where Media is referenced... but it should have errored about any of the other 10 Models that don't have tables above where this one is used in this file....
/Library/Ruby/Gems/1.8/gems/activesupport-2.3.8/lib/active_support/dependencies.rb:147:in `load_without_new_constant_marking'
/Library/Ruby/Gems/1.8/gems/activesupport-2.3.8/lib/active_support/dependencies.rb:147:in `load'
/Library/Ruby/Gems/1.8/gems/factory_girl-2.0.5/lib/factory_girl/find_definitions.rb:20:in `find_definitions'
/Library/Ruby/Gems/1.8/gems/factory_girl-2.0.5/lib/factory_girl/find_definitions.rb:19:in `each'
/Library/Ruby/Gems/1.8/gems/factory_girl-2.0.5/lib/factory_girl/find_definitions.rb:19:in `find_definitions'
/Library/Ruby/Gems/1.8/gems/factory_girl-2.0.5/lib/factory_girl/find_definitions.rb:15:in `each'
/Library/Ruby/Gems/1.8/gems/factory_girl-2.0.5/lib/factory_girl/find_definitions.rb:15:in `find_definitions'
/Library/Ruby/Gems/1.8/gems/factory_girl-2.0.5/lib/factory_girl/rails2.rb:6
/Library/Ruby/Gems/1.8/gems/rails-2.3.8/lib/initializer.rb:614:in `call'
/Library/Ruby/Gems/1.8/gems/rails-2.3.8/lib/initializer.rb:614:in `after_initialize'
/Library/Ruby/Gems/1.8/gems/rails-2.3.8/lib/initializer.rb:613:in `each'
/Library/Ruby/Gems/1.8/gems/rails-2.3.8/lib/initializer.rb:613:in `after_initialize'
/Library/Ruby/Gems/1.8/gems/rails-2.3.8/lib/initializer.rb:179:in `process'
/Library/Ruby/Gems/1.8/gems/rails-2.3.8/lib/initializer.rb:113:in `send'
/Library/Ruby/Gems/1.8/gems/rails-2.3.8/lib/initializer.rb:113:in `run'
/project/config/environment.rb:17   #why does it jump into the env? this is irrelevant to raking.
/Library/Ruby/Gems/1.8/gems/activesupport-2.3.8/lib/active_support/dependencies.rb:156:in `require'
/Library/Ruby/Gems/1.8/gems/activesupport-2.3.8/lib/active_support/dependencies.rb:156:in `require'
/Library/Ruby/Gems/1.8/gems/activesupport-2.3.8/lib/active_support/dependencies.rb:521:in `new_constants_in'
/Library/Ruby/Gems/1.8/gems/activesupport-2.3.8/lib/active_support/dependencies.rb:156:in `require'
/Library/Ruby/Gems/1.8/gems/rails-2.3.8/lib/tasks/misc.rake:4
/Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:636:in `call'
/Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:636:in `execute'
/Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:631:in `each'
/Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:631:in `execute'
/Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:597:in `invoke_with_call_chain'
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/monitor.rb:242:in `synchronize'
/Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:590:in `invoke_with_call_chain'
/Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:607:in `invoke_prerequisites'
/Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:604:in `each'
/Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:604:in `invoke_prerequisites'
/Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:596:in `invoke_with_call_chain'
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/monitor.rb:242:in `synchronize'
/Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:590:in `invoke_with_call_chain'
/Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:583:in `invoke'
/Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:2051:in `invoke_task'
/Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:2029:in `top_level'
/Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:2029:in `each'
/Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:2029:in `top_level'
/Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:2068:in `standard_exception_handling'
/Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:2023:in `top_level'
/Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:2001:in `run'
/Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:2068:in `standard_exception_handling'
/Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:1998:in `run'
/Library/Ruby/Gems/1.8/gems/rake-0.8.7/bin/rake:31
/usr/bin//rake:19:in `load'
/usr/bin//rake:19

EDIT:
the first migration file:
http://pastebin.com/49aJe2wv
the table it's erroring on doesn't even exist yet.

there are no tables in the test db.

EDIT2: Detail on the stack trace
factories/general:87

Factory.define :media, :class => Media do |m| #line 87 <----
  m.name "Alice is in an asian wonderland"
  m.document_file_name "alice_test_image.jpeg"
  m.document_content_type "image/jpeg"
  m.document_file_size "155548"
...
end

EDIT3:
Media.rb
http://pastebin.com/rZpdBTyq

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

长伴 2024-12-09 10:32:43

这看起来像是您的工厂或factory_girl/factory_girl_rails 的问题。

factory_girl_rails 在启动时加载所有工厂,我认为如果它们包含关联、验证等,那么 ActiveModel/ActiveRecord 就会被调用来检查模型。当然,在这种情况下,他们发现没有数据库可供检查。

我遇到了同样的问题,解决方案/解决方法是删除 gem 'factory_girl_rails' 并将其替换为普通的 'factory_girl',然后在 spec_helper 中手动加载工厂:

require 'factory_girl'
FactoryGirl.find_definitions

This looks like a problem with your factory, or perhaps factory_girl/factory_girl_rails.

factory_girl_rails loads all your factories at boot time, and I think if they include associations, validations etc, then ActiveModel/ActiveRecord gets called to inspect the models. Of course in this case they find that there is no database to inspect.

I had the same problem, and the solution/workaround is to remove the gem 'factory_girl_rails' and replace it with plain 'factory_girl', and then load the factories manually in spec_helper:

require 'factory_girl'
FactoryGirl.find_definitions
握住我的手 2024-12-09 10:32:43

发生这种情况是因为您正在测试环境中运行 db:migrate 任务,并且您的工厂插件正在尝试加载尚不存在的表的模型:

/Users/lprestonsegoiii/Work/GravityLabs/TinderBox/test/factories/ General.rb:87

您应该在开发数据库上运行迁移,然后使用 db:test:prepare 克隆数据库进行测试:

rake db:migrate
rake db:test:prepare

This is happening because you're running your db:migrate task in your test environment and your factory plugin is trying to load models for tables that don't exist yet:

/Users/lprestonsegoiii/Work/GravityLabs/TinderBox/test/factories/general.rb:87

You should run your migration on your development db and then use db:test:prepare to clone the database for tests:

rake db:migrate
rake db:test:prepare
淡忘如思 2024-12-09 10:32:43

首先,我们需要查看您的所有迁移。很可能您在创建迁移后删除了迁移或对其进行了修改,这会导致这种行为(或者如果您没有使用脚手架来生成迁移,那么您可能错误地编写了它们)。

在这种情况下,它可能尝试运行修改表的迁移,但在实际创建该表之前没有运行迁移,从而导致您看到的错误。

First off, we need to see all of your migrations. Chances are that you deleted a migration or modified it after it was created, which leads to this kind of behaviour (or if you did not use scaffolding to generate the migrations, then perhaps you wrote them incorrectly).

In this case, it is probably trying to run a migration that modifies the table, but there is no migration run before that which actually creates that table, leading to the error you see.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文