Ruby on Rails Rake 错误 [英] Ruby on Rails Rake Error

查看:42
本文介绍了Ruby on Rails Rake 错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

解决了这个问题,感谢这个论坛帖子:http://forums.aptana.com/viewtopic.php?f=20&t=7563&p=27407&hilit=libmysql.dll#p27407.谢谢大家!

Solved the problem, thanks to this forum post: http://forums.aptana.com/viewtopic.php?f=20&t=7563&p=27407&hilit=libmysql.dll#p27407. Thanks everyone!

我已经开始学习 RoR 并且一直在尝试使用 rake db:migrate 但我一直遇到同样的错误.我可以使用 C:\dev\railslist>mysql -u root railslist_development -p 连接到 MySQL 数据库.rake db:migrate --trace 产生以下结果:

I've started learning RoR and have been trying to use rake db:migrate but I keep getting the same error. I can connect to the MySQL database using C:\dev\railslist>mysql -u root railslist_development -p. rake db:migrate --trace produces the following:

C:\dev\railslist>rake db:migrate --trace
(in C:/dev/railslist)
** Invoke db:migrate (first_time)
** Invoke environment (first_time)
** Execute environment
** Execute db:migrate
rake aborted!
Mysql::Error: query: not connected: CREATE TABLE 'schema_migrations' ('version'
varchar(255) NOT NULL) ENGINE=InnoDB
C:/Ruby19/lib/ruby/gems/1.9.1/gems/activerecord-2.3.5/lib/active_record/connecti
on_adapters/abstract_adapter.rb:219:in 'rescue in log'
C:/Ruby19/lib/ruby/gems/1.9.1/gems/activerecord-2.3.5/lib/active_record/connecti
on_adapters/abstract_adapter.rb:202:in 'log'
C:/Ruby19/lib/ruby/gems/1.9.1/gems/activerecord-2.3.5/lib/active_record/connecti
on_adapters/mysql_adapter.rb:323:in 'execute'
C:/Ruby19/lib/ruby/gems/1.9.1/gems/activerecord-2.3.5/lib/active_record/connecti
on_adapters/abstract/schema_statements.rb:114:in 'create_table'
...

我的database.yml文件如下:

My database.yml file is as follows:

development:
  adapter: mysql
  database: railslist_development
  username: root
  password: **********
  host: localhost

  ...

抱歉,我搞混了...我可以使用 mysql connect localhost 连接到 MySQL 数据库 - 它产生一长串命令和变量.另外,如果我输入 mysql -h localhost -u root -p 我可以登录到 MySQL 提示.澄清一下:我可以通过命令行连接到 MySQL 数据库,但是在 RoR Rake 中会产生错误.

Sorry, I got mixed up there... I can connect to the MySQL database using mysql connect localhost - it produces a long list of commands and variables. Also if I enter mysql -h localhost -u root -p I can log into the MySQL prompt. So to clarify: I can connect to the MySQL database via the command line, however in RoR Rake produces an error.

推荐答案

这几乎肯定是因为您的 mysql 实例没有运行,或者您没有将 config/database.yml 配置为指向适合您环境的正确数据库(通常开发).这里有几件事可以尝试 -

This is almost definitely because your mysql instance is not running or you haven't configured config/database.yml to be pointed at the right database for your environment (usually Development). Here are a couple of things to try -

  • 检查您的 config/database.yml -你的主人在哪里(如果没有主人列出,它将连接到本地主机)
  • 尝试运行 mysql -h localhost 和查看mysql是否正在运行.

如果您无法连接到 localhost 数据库,那么问题就在那里,而不是 Rails.确保它正在运行,并且您的权限设置正确以允许从您的机器连接.此外,尝试以 root 用户身份从本地计算机进行连接,以查看是否存在更精细的问题(例如您启用了本地连接,但不适用于您在 Rails 中使用的用户).

If you're not able to connect to your localhost database, then the problem is there, not with Rails. Make sure you have it running, and that your permissions are set correctly to allow connection from your machine. Also, try connecting as root from your local machine, to see if it's a more granular issue (such as you have local connections enabled, but not for the user you're using in Rails).

编辑 2:在这种情况下,您的问题可能是您的数据库尚未创建.只需转到命令行并键入以下内容:

EDIT 2: In this case, your problem likely is that your database has not been created. Simply go to a command line and type the following:

mysql -u root -p -e '创建数据库 railslist_development;'

这应该会创建数据库并允许您运行迁移.

This should create the database and allow you to run your migration.

这篇关于Ruby on Rails Rake 错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆