uninitialized constant PGconn

Posted by Christopher Rigor on January 11, 2010 
Filed Under Ruby on Rails

I’m successfully using Postgres for development. My stack includes ruby 1.8.7, rails 2.3.4, and pg 0.8.0. One day, I get an error

NameError: uninitialized constant ActiveRecord::ConnectionAdapters::PostgreSQLAdapter::PGconn

I didn’t update Postgres or the pg gem so I don’t see a reason for it to stop working. Then I remember that I installed jruby and installed the activerecord adapater. Instead of using jgem install, I used gem install. This installed the gems (activerecord-jdbc-adapter, activerecord-jdbcmysql-adapter and jdbc-mysql) on my ruby 1.8.7 system. I left the gems installed thinking they wouldn’t cause any error.

So, if you encounter uninitialized constant ActiveRecord::ConnectionAdapters::PostgreSQLAdapter::PGconn check if you have the jdbc adapter gems for jruby.

I hope this helps someone.

Comments

  • Peter
    What is even more funny that a gem for MySQL causes such a weird problem for the Postgre adapter..
  • crigor
    It's not the mysql adapter that causes the error but the AR-JDBC. Nick Sieger explained this on his blog. http://blog.nicksieger.com/articles/2010/01/28/...
  • Peter
    Thanks a lot, dude! I had exactly the same problem and your post showed me the reason.
  • Andrew France
    Thank you!
  • Thanks, finally light! Very usefull your tip, but everything works fine when I removed the jdbc stuff but when I reinstall with jgem, everything stops to work again, how can I solve this?
  • crigor
    I didn't have this problem. jgem installs the gems on a different directory.
  • The sollution is comment the GEM_HOME and keep the JRuby native gems in the JRuby gem directory
blog comments powered by Disqus