views:

446

answers:

3

Hi,

I just switched to mac, I was previously working on Linux. I am trying to use posgresql for my project

When I start the server, it works fine.

Nevertheless when I use rake:db:migrate, it fails saying: Please install the postgresql adapter: gem install activerecord-postgresql-adapter (no such file to load -- pg)

I have the gem "pg" installed, and there are no such gem as activerecord-postgresql-adapter.

I find it weird that when I do ./script/server it works, but not when I do rake:db:migrate

Thnaks

+1  A: 

pg is the activerecord-postgresql-adapter gem, so that is what it is failing to find.

Since it is only failing from migrate, it might be rake is starting from a different version of ruby than console or script - do you have multiple versions of ruby?

Also since it is failing in rake, I would get the verbose (-v) output so you can see the stack trace, and see better what is going on, and at what point it tries to get pg but does not have the gem available. I have seen some weirdness with rake loading in a different order from rails start up, so that is not impossible.

There is a recent plugin that professes to help with pg migrations in rails, might help: http://github.com/alex3t/rails_on_pg

In case my guess above is completely unhelpful, here are some other places to look:

Project page for pg: https://rubyforge.org/projects/ruby-pg/

For more postgres on rails support: http://wiki.rubyonrails.org/database-support/postgres

Robby Russell write more about postgres than any other rails blogger I read: http://www.robbyonrails.com/articles/tag/postgresql

Andrew Kuklewicz
The more I think about it, I bet you installed rails/ruby from ports, but not rake, and so have different versions of these executables in different directories. Try this, and see if they are all in the same dir:which gem ruby rakeAlso, this guy got it to work using robby's post on RoR and postgres, on os x:http://joshkim.org/2009/02/15/postgresql-ruby-and-rails-win/
Andrew Kuklewicz
+1  A: 

You may need to install one or more of the following

  • pkg postgresql
  • pkg postgresql-devel
  • gem pg
Justice
+1  A: 

Check to make sure that you've consistently installed your gems as root. If you have pg installed into ~/.gems/ruby/1.8/gems (or similar), you may encounter this (or a similar) issue.

(Additional information for Andrew's answer, pretty much.)

corprew
I think it was actually active record gem that was installed into my local user directory and not as root. thanks a lot.
jules