1

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

4 Answers 4

1

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.)

Sign up to request clarification or add additional context in comments.

1 Comment

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

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

1 Comment

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 rake Also, this guy got it to work using robby's post on RoR and postgres, on os x: joshkim.org/2009/02/15/postgresql-ruby-and-rails-win
1

You may need to install one or more of the following

  • pkg postgresql
  • pkg postgresql-devel
  • gem pg

Comments

0

I just ran into this on Linux. In my case, the permissions were wrong: /usr/lib/ruby/gems/1.8/gems/pg-0.9.0 was set to 700.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.