DerNalia
DerNalia

Reputation: 123

Rake: says table doesn't exist when I try to migrate.... no duh, it doesn't exist, that's why I'm trying to migrate?

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

Upvotes: 3

Views: 4671

Answers (3)

jackpipe
jackpipe

Reputation: 981

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

Upvotes: 4

Winfield
Winfield

Reputation: 19145

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

Upvotes: 2

ankit
ankit

Reputation: 3358

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.

Upvotes: 0

Related Questions