Cannot seed database; not working because of refused connection?

孤人 提交于 2019-12-24 00:43:00

问题


When I try to seed my application I get the error:

No connection could be made because the - target machine actively refused it. - connect(2)

I believe the reason why is because I was having issues with mysql2 so I uninstalled it along with the MySQL 5.5 Servers and then switched to sqlite3. I think the server for mysql2 is running in the background so this could be the issue. How would I fix this? How would I turn off the Mysql2 local host server or whichever server it is that's causing this issue?

I am running on Windows 7 64-bit.

Rails 3.0.9
SQLite3 1.3.4

Thanks.

Note: I can migrate and drop fine.

Edit:

config/database.yml

# SQLite version 3.x
#   gem install sqlite3
development:
  adapter: sqlite3
  database: db/development.sqlite3
  pool: 5
  timeout: 5000

test:
  adapter: sqlite3
  database: db/test.sqlite3
  pool: 5
  timeout: 5000

production:
  adapter: sqlite3
  database: db/production.sqlite3
  pool: 5
  timeout: 5000

UPDATE:

I tried restarting the PC and also remade my application from scratch, still get the error. Disabled Windows Firewall/Comodo Firewall and tried again, still failure. I did a System Restore but this did not work either.

Here's the full rake db:seed: https://gist.github.com/1375566


SOLVED:

I have another application I ran rake db:seed in and it worked correctly, so as the accepted answer by clyfe pointed out, Sunspot was the issue. I put together again my application and stopped at adding sunspot and suddenly I got the error:

rake db:seed
(in C:/testagain)
Deleting database now...
rake aborted!
undefined method `searchable' for #<Class:0x52cdca0>

Which means the rake was reading my code inside of my UserPrice model that dealt with Sunspot:

class UserPrice < ActiveRecord::Base
  # Sunspot and Websolr configuration.
  #searchable do
   # text :product_name do
   #   product.name
   # end
 # end
end

I commented this out and was able to seed correctly. Then I went on to try sunspot using these commands in the following order:

rails g sunspot_rails:install
rake sunspot:solr:start (also un-comment model)
rake sunspot:reindex
rails server
rake db:seed

Everything works as it should.


回答1:


You are using Sunspot for indexing and search as I see from your gist https://gist.github.com/1375566
Make sure that the Solr server is started before you seed.

What happens is that:

  • when the model saves
  • it tries to send data to the Solr server for indexing
  • but it cannot connect

Possible issues:

  • the Solr server is not started
  • the Sunspot Solr connection is not configured corectly in /config/sunspot.yml
  • the port it's blocked by a firewall

If you haven't started a Solr server instance already, you can start the Sunspot-bundled Solr server with the following rake command:

rake sunspot:solr:start



回答2:


I dont think it is because of mysql, I think it is a firewall issue on the port that you are trying to access. You can test by stopping the service or using the mysql workbench to stop the server on that machine. I doubt that will resolve the issue, since the firewall may be interfering.




回答3:


Comment out the skip-networking in my.cnf in your MySQL configuration.



来源:https://stackoverflow.com/questions/8176211/cannot-seed-database-not-working-because-of-refused-connection

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!