Why I can't install postgresql with rails 4.0.

2020-07-22 09:59发布

问题:

first time on forum so i will try to be as specific as one can be, sorry for any possible typos ok?

I am relatively new to rails (less than a year), and i want to make a default project to work with it. I have always used sqlite3 in development and pg in production (heroku), but now i want to make things right (i've encountered problems with sqlite3 running ok but pg not) and use both pg in production and devlop.

I have spent 2 days searching foruns and all the anwsers are old or other versions/other OS.

I'll try to list the steps i took for setting up my stage: Here my configs:

-OS: Windows 7 64x
-Editor: Aptana Studio
-PostGresql
-Rails 4.0.0.rc1
-Ruby 2.0

  1. Download and Install postgresql-9.2.4-1-windows-x64
  2. Set a default Password to postgresql
  3. Create an Role "my_user" in postgresql with all privilegies
  4. Create an testing database "rails_test"
  5. Open Aptana Studio and init an new default project going to the project folder and than running "rails new . -d postgresql" for generate the new project.
  6. Install the pg gem "gem install pg" "gem list" shows the pg gem correctly
  7. configure "database.yml" for using the correct username and password

    development:
      adapter: postgresql
      encoding: unicode
      database: rails_test
      pool: 5
      username: my_user
      password: 12345
    
  8. Running some commands in ruby like "gem update", "bundle install"

then when i try to generate an model and use rake db:migrate i get the following error:

    Specified 'postgresql' for database adapter, but the gem is not loaded. Add `gem 'pg'` to your Gemfile.

and it's true if i run "bundle show pg" i get the message:

    Could not find gem 'pg'. Did you mean pg? 

If i open my gemfile the pg gem is there, but the bundler is not getting it !

Any ideias to help this little amateur?

TNX !

回答1:

I had this problem and solved it by using the 32bit version of ruby rather than the 64bit. You need to make sure the devkit matches up to your version as well. So if you have the 64 bit version of that installed then that will need to be changed too.



回答2:

(Windows 7 x64, Ruby2.0.0p247-x64, Rails4.0.0, Postgresql 9.2.4 x64, pg 0.15.1, mysql2 0.3.11) There seems to be a platform detection/verification problem with bundler. While what I did is a hack of the Gemfile.lock file (I know, I know...), I have a (hopefully) temporary solution:

Edit Gemfile.lock, and

  • Find the line for 'pg':
 multi_json (1.7.7)
 pg (0.15.1-x86-mingw32)
 polyglot (0.3.3)
  • Copy the line, and modify the new copy to :
 multi_json (1.7.7)
 pg (0.15.1-x64-mingw32)
 pg (0.15.1-x86-mingw32)
 polyglot (0.3.3)

This is how the x64 version of the installed gem announces itself when you ask to list it (gem list pg).

For anyone who cares, the exact same problem was (sometimes) encountered with the mysql2 gem.