简体   繁体   English

ActiveRecord :: ConnectionNotEstablished Ruby on Rails入门

[英]ActiveRecord::ConnectionNotEstablished getting started with Ruby on Rails

I am absolutely new to Ruby on Rails and I'm following a book that's written as a tutorial, but it is a bit outdated. 我绝对是Ruby on Rails的新手,我正在看一本写成教程的书,但这有点过时了。

When I run the server and browse localhost:3000 something is not working right, I get the following error: ActiveRecord::ConnectionNotEstablished 当我运行服务器并浏览localhost:3000某些方法无法正常运行,我收到以下错误消息: ActiveRecord::ConnectionNotEstablished

MySQL is installed in my computer, the databases are created and all of this works in other example applications I have been giving a look to. 我的计算机上安装了MySQL,创建了数据库,并且所有这些在我一直关注的其他示例应用程序中都可以使用。

This is the databases.yml file: 这是databases.yml文件:

development:
  adapter: mysql2
  database: emporium_development
  username: emporium
  password: hacked

test:
  adapter: mysql2
  database: emporium_test
  username: emporium
  password: hacked

I made sure the mysql2 gem is installed like this: gem install mysql2 我确保像这样gem install mysql2gem install mysql2

Shed some light on me please. 请给我一些照明。

First setup your gems by running 首先通过运行来设置您的宝石

Bundle install

Then your database needs to be created: 然后,需要创建数据库:

rake db:create

If you have some pending migrations (and if you don't this can still be run, it just won't do anything): 如果您有一些待处理的迁移(如果没有,则仍然可以运行,它什么也不会做):

rake db:migrate

This should setup a database that works, provided you gave the correct password. 如果您提供了正确的密码,这将设置一个可以正常工作的数据库。

Note that if you already have a database that you want to get rid of, you can run 请注意,如果您已经有要删除的数据库,则可以运行

rake db:drop

and then try to create the database again. 然后尝试再次创建数据库。

Does any of this solve your problem ? 有没有解决您的问题?

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

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