views:

50

answers:

2

I just created a simple migration to an existing project. This project uses RMagick, and when I call rake db:migrate the migration fails thus:

Dans-iMac-335:myserver apple$ rake db:migrate
(in /Users/apple/Documents/projects/electionjoy/glowing-mist-78)
dlopen(/Users/apple/.gem/ruby/1.8/gems/rmagick-2.12.1/lib/RMagick2.bundle, 9): Library not loaded: /usr/local/libpng/lib/libpng12.0.dylib
  Referenced from: /Users/apple/.gem/ruby/1.8/gems/rmagick-2.12.1/lib/RMagick2.bundle
  Reason: image not found - /Users/apple/.gem/ruby/1.8/gems/rmagick-2.12.1/lib/RMagick2.bundle
/Users/apple/.gem/ruby/1.8/gems/rmagick-2.12.1/lib/RMagick2.bundle
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/rubygems/custom_require.rb:31:in `require'
/Users/apple/.gem/ruby/1.8/gems/activesupport-2.2.2/lib/active_support/dependencies.rb:153:in `require'
/Users/apple/.gem/ruby/1.8/gems/activesupport-2.2.2/lib/active_support/dependencies.rb:521:in `new_constants_in'
/Users/apple/.gem/ruby/1.8/gems/activesupport-2.2.2/lib/active_support/dependencies.rb:153:in `require'
/Users/apple/.gem/ruby/1.8/gems/rmagick-2.12.1/lib/RMagick.rb:11

There's more, but this is where it looks for RMagick. The bundle exists at that location.

Why would a database migration require the RMagick gem be present? And what is the fix for this problem? I'm using Rails 2.2.2 on OS X 10.6, here's the local gem list :

* LOCAL GEMS *

actionmailer (2.3.8, 2.3.5, 2.2.2)
actionpack (2.3.8, 2.3.5, 2.2.2)
actionwebservice (1.2.3)
activemerchant (1.5.1)
activerecord (2.3.8, 2.3.5, 2.2.2)
activerecord-tableless (0.1.0)
activeresource (2.3.8, 2.3.5, 2.3.3, 2.2.2)
activesupport (2.3.8, 2.3.5, 2.3.3, 2.2.2)
authlogic (2.1.5)
authlogic-oid (1.0.4)
aws-s3 (0.6.2)
builder (2.1.2)
capistrano (2.5.9)
cgi_multipart_eof_fix (2.5.0)
chronic (0.2.3)
configuration (1.1.0)
daemons (1.0.10)
facebooker (1.0.62)
faker (0.3.1)
fastthread (1.0.7)
gem_plugin (0.2.3)
google-geocode (1.2.1)
heroku (1.8.5, 1.3.0, 1.0.1)
highline (1.5.1)
hoe (2.3.3)
hpricot (0.8.1)
json (1.1.9)
json_pure (1.2.4, 1.1.9)
launchy (0.3.3)
less (1.2.20)
libxml-ruby (1.1.3)
mime-types (1.16)
minitest (1.4.2)
mongrel (1.1.5)
mutter (0.5.3)
mysql (2.8.1)
net-scp (1.0.2)
net-sftp (2.0.2)
net-ssh (2.0.15)
net-ssh-gateway (1.0.1)
nokogiri (1.3.3)
packet (0.1.15)
paperclip (2.3.1.1)
passenger (2.2.5)
pg (0.9.0, 0.8.0)
polyglot (0.3.1)
postgres (0.7.9.2008.01.28)
rack (1.1.0, 1.0.1, 1.0.0)
radiant (0.8.1)
rails (2.3.8, 2.3.5, 2.2.2)
rake (0.8.7)
rc-rest (3.0.0)
RedCloth (4.2.3)
rest-client (1.3.1, 1.0.3)
rmagick (2.13.1, 2.12.1)
ruby-openid (2.1.7)
rubyforge (2.0.4, 2.0.2)
rubygems-update (1.3.7, 1.3.5)
searchlogic (2.3.5)
sequel (3.0.0)
sinatra (0.9.2)
spree (0.10.2)
sqlite3-ruby (1.2.5, 1.0.1)
state_machine (0.8.0)
stringex (1.0.3)
taps (0.2.26, 0.2.19)
thor (0.9.9)
treetop (1.4.8)
whenever (0.3.7)
will_paginate (2.3.11)
xml-simple (1.0.12)
A: 

I don't know why your machine is not finding it, but rake tasks in rails require any gem that your app is configured to use, even if the code is not called.

If it didn't, some other call (that is overridden by a missing gem) might happen and result in unexpected behavior.

Tim Hoolihan
A: 

The entire Rails environment is loaded when executing a Rake task such as performing a database migration and that includes gem dependencies. I got bitten by the same thing recently when resurrecting an old project and I couldn't migrate the database until I'd installed certain unrelated gems.

From looking at the information in the stack trace (Library not loaded: /usr/local/libpng/lib/libpng12.0.dylib) I would suspect that ImageMagick is not installed correctly on your machine. You might want to give this script a try.

John Topley
Doesn't the entire Rails environment get loaded when the application runs as well? It runs without problems, but it dies on rake db:migrate. Work-around : disable references to rmagick in environment.rb while migrating…
Dan Donaldson