Ruby on Rails:ActiveRecord :: ConnectionNotEstablished

时间:2012-01-27 15:10:25

标签: mysql ruby-on-rails

我正在尝试为我的Ruby on Rails应用程序启用mySQL。我在Rails中为Project生成了一个模型,使用了bundle exec rake db:migrate,并添加了myapp_dev数据库(mySQL)所需的所有字段。但是当我去localhost:3000/projects时,我收到了这个错误:

ActiveRecord::ConnectionNotEstablished

activerecord (3.2.0) lib/active_record/connection_adapters/abstract/connection_pool.rb:374:in `retrieve_connection'
activerecord (3.2.0) lib/active_record/connection_adapters/abstract/connection_specification.rb:168:in `retrieve_connection'
activerecord (3.2.0) lib/active_record/connection_adapters/abstract/connection_specification.rb:142:in `connection'
activerecord (3.2.0) lib/active_record/query_cache.rb:67:in `rescue in call'
activerecord (3.2.0) lib/active_record/query_cache.rb:61:in `call'
activerecord (3.2.0) lib/active_record/connection_adapters/abstract/connection_pool.rb:443:in `call'
actionpack (3.2.0) lib/action_dispatch/middleware/callbacks.rb:28:in `block in call'
activesupport (3.2.0) lib/active_support/callbacks.rb:405:in `_run__93413930__call__216979767__callbacks'
activesupport (3.2.0) lib/active_support/callbacks.rb:405:in `__run_callback'
activesupport (3.2.0) lib/active_support/callbacks.rb:385:in `_run_call_callbacks'
activesupport (3.2.0) lib/active_support/callbacks.rb:81:in `run_callbacks'
actionpack (3.2.0) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
actionpack (3.2.0) lib/action_dispatch/middleware/reloader.rb:65:in `call'
actionpack (3.2.0) lib/action_dispatch/middleware/remote_ip.rb:31:in `call'
actionpack (3.2.0) lib/action_dispatch/middleware/debug_exceptions.rb:16:in `call'
actionpack (3.2.0) lib/action_dispatch/middleware/show_exceptions.rb:56:in `call'
railties (3.2.0) lib/rails/rack/logger.rb:26:in `call_app'
railties (3.2.0) lib/rails/rack/logger.rb:16:in `call'
actionpack (3.2.0) lib/action_dispatch/middleware/request_id.rb:22:in `call'
rack (1.4.1) lib/rack/methodoverride.rb:21:in `call'
rack (1.4.1) lib/rack/runtime.rb:17:in `call'
activesupport (3.2.0) lib/active_support/cache/strategy/local_cache.rb:72:in `call'
rack (1.4.1) lib/rack/lock.rb:15:in `call'
actionpack (3.2.0) lib/action_dispatch/middleware/static.rb:53:in `call'
railties (3.2.0) lib/rails/engine.rb:479:in `call'
railties (3.2.0) lib/rails/application.rb:220:in `call'
rack (1.4.1) lib/rack/content_length.rb:14:in `call'
railties (3.2.0) lib/rails/rack/log_tailer.rb:14:in `call'
rack (1.4.1) lib/rack/handler/webrick.rb:59:in `service'
/usr/share/ruby-rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/webrick/httpserver.rb:138:in `service'
/usr/share/ruby-rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/webrick/httpserver.rb:94:in `run'
/usr/share/ruby-rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/webrick/server.rb:191:in `block in start_thread'

这是什么问题? 这是我的database.yml

development:
  adapter: mysql
  encoding: utf8
  database: myapp_dev
  username: root
  password: root
  host: localhost

2 个答案:

答案 0 :(得分:0)

好像,你的MySql数据库连接无法正常工作,请尝试使用以下命令登录我的sql服务器

mysql -uroot -proot myapp_dev

确保这样做有效,如果这样可行,您的应用也应该能够访问数据库,如果您收到任何错误,在此处发布错误将有人帮助您

欢呼声

答案 1 :(得分:0)

尝试将'dev'部分放在database.yml的顶部:

dev:
  adapter: mysql
  encoding: utf8
  database: myapp_dev
  username: root
  password: root
  host: localhost

并保留'开发'部分。