mysql2postgres icon indicating copy to clipboard operation
mysql2postgres copied to clipboard

`initialize': undefined method `connect' for PG:Module on OSX

Open nlively opened this issue 8 years ago • 12 comments

I'm using ruby 1.9.3-p551 with RVM on an OSX Yosemite installation. Keep running into this error:

WARN: Unresolved specs during Gem::Specification.reset:
      postgres-pr (~> 0.6)
      activerecord (~> 3.2)
WARN: Clearing out unresolved specs.
Please report a bug if this causes problems.
/Users/myself/.rvm/gems/ruby-1.9.3-p551/gems/pg-0.18.2/lib/pg/connection.rb:230: warning: already initialized constant PGconn
/Users/myself/.rvm/gems/ruby-1.9.3-p551/gems/pg-0.18.2/lib/pg/result.rb:26: warning: already initialized constant PGresult
/Users/myself/.rvm/gems/ruby-1.9.3-p551@global/gems/mysqltopostgres-0.2.20/lib/mysql2psql/connection.rb:46:in `initialize': undefined method `connect' for PG:Module (NoMethodError)
    from /Users/myself/.rvm/gems/ruby-1.9.3-p551@global/gems/mysqltopostgres-0.2.20/lib/mysql2psql/postgres_db_writer.rb:12:in `new'
    from /Users/myself/.rvm/gems/ruby-1.9.3-p551@global/gems/mysqltopostgres-0.2.20/lib/mysql2psql/postgres_db_writer.rb:12:in `initialize'
    from /Users/myself/.rvm/gems/ruby-1.9.3-p551@global/gems/mysqltopostgres-0.2.20/lib/mysqltopostgres.rb:49:in `new'
    from /Users/myself/.rvm/gems/ruby-1.9.3-p551@global/gems/mysqltopostgres-0.2.20/lib/mysqltopostgres.rb:49:in `convert'
    from /Users/myself/.rvm/gems/ruby-1.9.3-p551@global/gems/mysqltopostgres-0.2.20/bin/mysqltopostgres:23:in `<top (required)>'
    from /Users/myself/.rvm/rubies/ruby-1.9.3-p551/bin/mysqltopostgres:23:in `load'
    from /Users/myself/.rvm/rubies/ruby-1.9.3-p551/bin/mysqltopostgres:23:in `<main>'
    from /Users/myself/.rvm/gems/ruby-1.9.3-p551/bin/ruby_executable_hooks:15:in `eval'
    from /Users/myself/.rvm/gems/ruby-1.9.3-p551/bin/ruby_executable_hooks:15:in `<main>'

Never seen that error before this task I'm doing, and I can't seem to find it referenced online.

nlively avatar Sep 02 '15 16:09 nlively

I've been continuing to research this and play around with the code. Seems like the problem goes away when the 'postgres-pr' gem is excluded from the Gemfile. Looks like these gems conflict in their definition of the PG namespace.

nlively avatar Sep 02 '15 16:09 nlively

Can you create a Pull Request with the suggested fix?

paazmaya avatar Nov 25 '15 12:11 paazmaya

+1, OSX, Yosemite, Ruby 2.1.7 / RVM

/Users/liltomato/.rvm/gems/ruby-2.1.7/gems/pg-0.18.4/lib/pg/connection.rb:230: warning: already initialized constant PGconn
/Users/liltomato/.rvm/gems/ruby-2.1.7/gems/postgres-pr-0.7.0/lib/postgres-pr/postgres-compat.rb:6: warning: previous definition of PGconn was here
/Users/liltomato/.rvm/gems/ruby-2.1.7/gems/pg-0.18.4/lib/pg/result.rb:26: warning: already initialized constant PGresult
/Users/liltomato/.rvm/gems/ruby-2.1.7/gems/postgres-pr-0.7.0/lib/postgres-pr/postgres-compat.rb:69: warning: previous definition of PGresult was here
/Users/liltomato/.rvm/gems/ruby-2.1.7@global/gems/mysqltopostgres-0.3.0/bin/mysqltopostgres:30:in `<top (required)>': '' does not exist (RuntimeError)
    from /Users/liltomato/.rvm/rubies/ruby-2.1.7/bin/mysqltopostgres:23:in `load'
    from /Users/liltomato/.rvm/rubies/ruby-2.1.7/bin/mysqltopostgres:23:in `<main>'
    from /Users/liltomato/.rvm/gems/ruby-2.1.7/bin/ruby_executable_hooks:15:in `eval'
    from /Users/liltomato/.rvm/gems/ruby-2.1.7/bin/ruby_executable_hooks:15:in `<main>'

ljlozano avatar Nov 26 '15 00:11 ljlozano

+1

ideaoforder avatar Nov 30 '15 19:11 ideaoforder

+1, OSX, Yosemite, Ruby 2.1.7 / RVM

Any updates on this?

WARN: Unresolved specs during Gem::Specification.reset:
      test-unit (~> 2.1)
WARN: Clearing out unresolved specs.
Please report a bug if this causes problems.
/Users/Guillo/.rvm/gems/ruby-2.1.7/gems/pg-0.18.4/lib/pg/connection.rb:230: warning: already initialized constant PGconn
/Users/Guillo/.rvm/gems/ruby-2.1.7/gems/postgres-pr-0.7.0/lib/postgres-pr/postgres-compat.rb:6: warning: previous definition of PGconn was here
/Users/Guillo/.rvm/gems/ruby-2.1.7/gems/pg-0.18.4/lib/pg/result.rb:26: warning: already initialized constant PGresult
/Users/Guillo/.rvm/gems/ruby-2.1.7/gems/postgres-pr-0.7.0/lib/postgres-pr/postgres-compat.rb:69: warning: previous definition of PGresult was here
/Users/Guillo/.rvm/gems/ruby-2.1.7@global/gems/mysqltopostgres-0.3.0/bin/mysqltopostgres:30:in `<top (required)>': '' does not exist (RuntimeError)
    from /Users/Guillo/.rvm/rubies/ruby-2.1.7/bin/mysqltopostgres:23:in `load'
    from /Users/Guillo/.rvm/rubies/ruby-2.1.7/bin/mysqltopostgres:23:in `<main>'
    from /Users/Guillo/.rvm/gems/ruby-2.1.7/bin/ruby_executable_hooks:15:in `eval'
    from /Users/Guillo/.rvm/gems/ruby-2.1.7/bin/ruby_executable_hooks:15:in `<main>'

guillosaracco avatar Jan 07 '16 18:01 guillosaracco

+1, thanks for ths repo!

nitsujri avatar Jan 12 '16 14:01 nitsujri

I have a very similar issue on El Capitan

$ mysqltopostgres
/Users/samuelstickland/.rvm/gems/ruby-2.3.0/gems/pg-0.18.4/lib/pg/connection.rb:230: warning: already initialized constant PGconn
/Users/samuelstickland/.rvm/gems/ruby-2.3.0/gems/postgres-pr-0.7.0/lib/postgres-pr/postgres-compat.rb:6: warning: previous definition of PGconn was here
/Users/samuelstickland/.rvm/gems/ruby-2.3.0/gems/pg-0.18.4/lib/pg/result.rb:26: warning: already initialized constant PGresult
/Users/samuelstickland/.rvm/gems/ruby-2.3.0/gems/postgres-pr-0.7.0/lib/postgres-pr/postgres-compat.rb:69: warning: previous definition of PGresult was here
/Users/samuelstickland/.rvm/gems/ruby-2.3.0/gems/mysqltopostgres-0.3.0/bin/mysqltopostgres:30:in `<top (required)>': '' does not exist (RuntimeError)
    from /Users/samuelstickland/.rvm/gems/ruby-2.3.0/bin/mysqltopostgres:23:in `load'
    from /Users/samuelstickland/.rvm/gems/ruby-2.3.0/bin/mysqltopostgres:23:in `<main>'
    from /Users/samuelstickland/.rvm/gems/ruby-2.3.0/bin/ruby_executable_hooks:15:in `eval'
    from /Users/samuelstickland/.rvm/gems/ruby-2.3.0/bin/ruby_executable_hooks:15:in `<main>'

samstickland avatar May 25 '16 16:05 samstickland

Same here

$ mysqltopostgres
/Library/Ruby/Gems/2.0.0/gems/pg-0.18.4/lib/pg/connection.rb:230: warning: already initialized constant PGconn
/Library/Ruby/Gems/2.0.0/gems/postgres-pr-0.7.0/lib/postgres-pr/postgres-compat.rb:6: warning: previous definition of PGconn was here
/Library/Ruby/Gems/2.0.0/gems/pg-0.18.4/lib/pg/result.rb:26: warning: already initialized constant PGresult
/Library/Ruby/Gems/2.0.0/gems/postgres-pr-0.7.0/lib/postgres-pr/postgres-compat.rb:69: warning: previous definition of PGresult was here
/Library/Ruby/Gems/2.0.0/gems/mysqltopostgres-0.3.0/bin/mysqltopostgres:30:in `<top (required)>': '' does not exist (RuntimeError)
    from /usr/local/bin/mysqltopostgres:23:in `load'
    from /usr/local/bin/mysqltopostgres:23:in `<main>'

lucandrade avatar May 26 '16 03:05 lucandrade

I get the same error as lucandrade.

eniacization avatar May 26 '16 08:05 eniacization

All I can say is that Pull Requests are more than welcome, as I do not have the resources for doing this at the moment

paazmaya avatar May 30 '16 09:05 paazmaya

Did anyone ever figure this out? Getting same error as @lucandrade

ritec avatar Aug 22 '16 20:08 ritec

I followed the advice of removing references to the postgres-pr gem, since I'm using MRI. (This fix won't work for JRUBY users, sowwy.)

See: https://github.com/brettimus/mysql2postgres/tree/issue_80_workaround

After hitting issue #73, was able to get it to work. (This comment had the fix that did the trick for me.)

Worth noting: if you run the command from your terminal, the "environment" defaults to "development". I.e., the script will try to access the postgres database defined under the development key in your config file. If you want to change that, you should specify a RAILS_ENV variable.

E.g., running

RAILS_ENV=production mysqltopostgres config.yml

Would use the "production" database defined below:

mysql2psql:
  mysql:
    <<: *pii

  destination:
    production:
      <<: *production

brettimus avatar Oct 01 '16 00:10 brettimus