如何处理 Ruby on Rails 错误:“请安装 postgresql 适配器:`gem install activerecord-postgresql-adapter'”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1664364/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to handle Ruby on Rails error: "Please install the postgresql adapter: `gem install activerecord-postgresql-adapter'"
提问by user71268
Running a Ruby on Rails (RoR) app or Ruby code which uses the ActiveRecord framework, you get the error message:
运行使用 ActiveRecord 框架的 Ruby on Rails (RoR) 应用程序或 Ruby 代码,您会收到错误消息:
Please install the postgresql adapter:
gem install activerecord-postgresql-adapter
请安装 postgresql 适配器:
gem install activerecord-postgresql-adapter
Trying to run:
试图运行:
gem install activerecord-postgresql-adapter
also fails, leaving you at a loss.
也失败了,让你不知所措。
回答by mcr
The problem is not what anyone wrote. The problem is that the name of the postgresql database adapter is "postgresql", not "postgres", though the name of the GEM is "pg".
问题不在于有人写了什么。问题是 postgresql 数据库适配器的名称是“postgresql”,而不是“postgres”,尽管 GEM 的名称是“pg”。
The definition in the database.yml file should include
database.yml 文件中的定义应该包括
adapter: postgresql
回答by jstreebin
Here's the answer I got from Heroku and it worked for me (after trying different pg gems, adapters, and everything else on the 10 other posts about this)
这是我从 Heroku 得到的答案,它对我有用(在尝试了不同的 pg gem、适配器以及其他 10 篇有关此问题的其他所有内容之后)
1) add the line: gem 'pg' to your Gemfile.
1) 将行: gem 'pg' 添加到您的 Gemfile 中。
2) Run the command bundle install to install the gem into your bundle.
2) 运行命令 bundle install 将 gem 安装到你的包中。
3) Stage the Gemfile and Gemfile.lock changes: git add Gemfile Gemfile.lock
3) 暂存 Gemfile 和 Gemfile.lock 更改: git add Gemfile Gemfile.lock
4) Commit the changes: git commit -m "Install the pg gem"
4) 提交更改: git commit -m "Install the pg gem"
5) Redeploy to heroku: git push heroku master
5)重新部署到heroku:git push heroku master
回答by user71268
This means you don't have the new ‘pg' postgresql library installed. This is easily fixed with a bit of:
这意味着您没有安装新的“pg” postgresql 库。这很容易解决:
sudo gem install pg
I (Dov) found other solutions on the web which described setting GEM_HOME and adding ~/.gem/ruby/vers/bin to your PATH, but they didn't work. This solution above was provided by Mark Mansour on his blog State of Flux at: http://stateofflux.com/2008/7/13/activerecord-postgresql-adapter-in-rails-2-1/
我(Dov)在网上找到了其他解决方案,其中描述了设置 GEM_HOME 并将 ~/.gem/ruby/vers/bin 添加到您的 PATH,但它们没有用。上述解决方案由 Mark Mansour 在他的博客 State of Flux 上提供:http: //stateofflux.com/2008/7/13/activerecord-postgresql-adapter-in-rails-2-1/
回答by Chad
There is one more deeply hidden condition that will also cause this error.
还有一个更深层隐藏的情况也会导致此错误。
If you have a local environment variable DATABASE_URL=postgres://mehmehmehset, then some gem (I suspect Heroku) causes the app to think that Postgres is required even if it's nowhere in your configs. Kill that env variable and you should be fine.
如果您设置了本地环境变量DATABASE_URL=postgres://mehmehmeh,那么一些 gem(我怀疑 Heroku)会导致应用程序认为需要 Postgres,即使它在您的配置中无处可见。杀死那个 env 变量,你应该没问题。
回答by Daniel134
You can try this
你可以试试这个
On debian(squeeze):
在 debian(挤压)上:
aptitude install libdbd-pg-ruby
回答by Doug
Check database.yml environment db is correct. If it is postgresql, you might need to change it to refer to mysql2 or whatever db your using for your given environment.
检查 database.yml 环境 db 是否正确。如果它是 postgresql,您可能需要将其更改为引用 mysql2 或您在给定环境中使用的任何数据库。
回答by KurtB
sudo apt-get install ruby1.8-dev
须藤 apt-get 安装 ruby1.8-dev
then...
然后...
gem install pg
宝石安装 pg
Worked for me!
对我来说有效!
回答by tomcopeland
I did a little roundup of the current state of Ruby + PostgreSQL database drivers on railsonpostgresql.com; I think sudo gem install pgis probably the one you want.
我在railsonpostgresql.com上对 Ruby + PostgreSQL 数据库驱动程序的当前状态做了一些综述;我想sudo gem install pg可能是你想要的。
回答by Viet Pham
While trying out different search results, I installed a bunch. What finally got my environment to stop complaining with this message: "Please install the postgresql adapter: gem install activerecord-postgresql-adapter" was:
在尝试不同的搜索结果时,我安装了一堆。最终让我的环境停止抱怨此消息的原因是:“请安装 postgresql 适配器:gem install activerecord-postgresql-adapter”是:
I removed all gems relating to the adapter such as: sudo gem uninstall activerecord-jdbc-adapter; sudo gem uninstall activerecord-jdbcpostgresql-adapter; sudo gem uninstall activerecord-postgresql-adapter; sudo gem uninstall jdbc-postgres;
I also removed references to adapter as followed inside my Gemfile: gem 'activerecord-jdbcpostgresql-adapter'
Leave only pg (0.15.1) installed (to check for existence of pg, do "gem list")
我删除了与适配器相关的所有 gem,例如: sudo gem uninstall activerecord-jdbc-adapter; sudo gem 卸载 activerecord-jdbcpostgresql-adapter; sudo gem 卸载 activerecord-postgresql-adapter; sudo gem 卸载 jdbc-postgres;
我还在我的 Gemfile 中删除了对适配器的引用: gem 'activerecord-jdbcpostgresql-adapter'
只安装 pg (0.15.1)(检查 pg 是否存在,执行“gem list”)
Then running "rake db:create" works. So, I guess pg is the latest and works. However, it does not get used when other broken adapter gems are around.
然后运行“rake db:create”就可以了。所以,我猜 pg 是最新的并且有效。但是,当周围有其他损坏的适配器宝石时,它不会被使用。

