简体   繁体   English

Ruby on Rails:ActiveRecord ::连接未建立

[英]Ruby on Rails: ActiveRecord::ConnectionNotEstablished

I'm trying to enable mySQL for my Ruby on Rails application. 我正在尝试为Ruby on Rails应用程序启用mySQL。 I generated a model for Project in Rails, used bundle exec rake db:migrate , and it added all fields required to myapp_dev database (mySQL). 我为Rails中的Project生成了一个模型,使用了bundle exec rake db:migrate ,并将其添加到myapp_dev数据库(mySQL)所需的所有字段。 But when I go to localhost:3000/projects , I get this error: 但是当我转到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'

What is the problem here? 这里有什么问题? Here is my database.yml 这是我的database.yml

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

Seems like, your MySql db connection is not working, try to login to your my sql server with following command 似乎您的MySql数据库连接不起作用,请尝试使用以下命令登录到您的我的sql服务器

mysql -uroot -proot myapp_dev

Make sure this works, if this works your app also should be able to access the DB, If you get any error, posting the error here will get someone to help you 确保此方法有效,如果此方法有效,则您的应用程序也应该能够访问数据库。如果遇到任何错误,在此处发布错误将帮助您

cheers 干杯

Try putting 'dev' section on the top of database.yml: 尝试将“ dev”部分放在database.yml的顶部:

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

and leave 'development' section as it is. 并保留“开发”部分。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM