0

我刚刚使用 Ruby on Rails 设置了 MySQL。我创建了一个新的 rails 项目,提供以下命令

rails new test1 –d mysql

该项目已成功创建,但是当我给出以下命令时出现错误

rake db:create

错误是

C:\Users\HP\test1>rake db:create
rake aborted!
(<unknown>): did not find expected key while parsing a block mapping at line 11
column 1

Tasks: TOP => db:create => db:load_config
(See full trace by running task with --trace)

运行跟踪命令时收到以下消息

C:\Users\HP\test1>rake db:create --trace
** Invoke db:create (first_time)
** Invoke db:load_config (first_time)
** Invoke rails_env (first_time)
** Execute rails_env
** Execute db:load_config
rake aborted!
(<unknown>): did not find expected key while parsing a block mapping at line 11
column 1
C:/Ruby200/lib/ruby/2.0.0/psych.rb:205:in `parse'
C:/Ruby200/lib/ruby/2.0.0/psych.rb:205:in `parse_stream'
C:/Ruby200/lib/ruby/2.0.0/psych.rb:153:in `parse'
C:/Ruby200/lib/ruby/2.0.0/psych.rb:129:in `load'
C:/Ruby200/lib/ruby/gems/2.0.0/gems/railties-3.1.1/lib/rails/application/configu
ration.rb:106:in `database_configuration'
C:/Ruby200/lib/ruby/gems/2.0.0/gems/activerecord-3.1.1/lib/active_record/railtie
s/databases.rake:6:in `block (2 levels) in <top (required)>'
C:/Ruby200/lib/ruby/gems/2.0.0/gems/rake-10.1.0/lib/rake/task.rb:236:in `call'
C:/Ruby200/lib/ruby/gems/2.0.0/gems/rake-10.1.0/lib/rake/task.rb:236:in `block i
n execute'
C:/Ruby200/lib/ruby/gems/2.0.0/gems/rake-10.1.0/lib/rake/task.rb:231:in `each'
C:/Ruby200/lib/ruby/gems/2.0.0/gems/rake-10.1.0/lib/rake/task.rb:231:in `execute
'
C:/Ruby200/lib/ruby/gems/2.0.0/gems/rake-10.1.0/lib/rake/task.rb:175:in `block i
n invoke_with_call_chain'
C:/Ruby200/lib/ruby/2.0.0/monitor.rb:211:in `mon_synchronize'
C:/Ruby200/lib/ruby/gems/2.0.0/gems/rake-10.1.0/lib/rake/task.rb:168:in `invoke_
with_call_chain'
C:/Ruby200/lib/ruby/gems/2.0.0/gems/rake-10.1.0/lib/rake/task.rb:197:in `block i
n invoke_prerequisites'
C:/Ruby200/lib/ruby/gems/2.0.0/gems/rake-10.1.0/lib/rake/task.rb:195:in `each'
C:/Ruby200/lib/ruby/gems/2.0.0/gems/rake-10.1.0/lib/rake/task.rb:195:in `invoke_
prerequisites'
C:/Ruby200/lib/ruby/gems/2.0.0/gems/rake-10.1.0/lib/rake/task.rb:174:in `block i
n invoke_with_call_chain'
C:/Ruby200/lib/ruby/2.0.0/monitor.rb:211:in `mon_synchronize'
C:/Ruby200/lib/ruby/gems/2.0.0/gems/rake-10.1.0/lib/rake/task.rb:168:in `invoke_
with_call_chain'
C:/Ruby200/lib/ruby/gems/2.0.0/gems/rake-10.1.0/lib/rake/task.rb:161:in `invoke'

C:/Ruby200/lib/ruby/gems/2.0.0/gems/rake-10.1.0/lib/rake/application.rb:149:in `
invoke_task'
C:/Ruby200/lib/ruby/gems/2.0.0/gems/rake-10.1.0/lib/rake/application.rb:106:in `
block (2 levels) in top_level'
C:/Ruby200/lib/ruby/gems/2.0.0/gems/rake-10.1.0/lib/rake/application.rb:106:in `
each'
C:/Ruby200/lib/ruby/gems/2.0.0/gems/rake-10.1.0/lib/rake/application.rb:106:in `
block in top_level'
C:/Ruby200/lib/ruby/gems/2.0.0/gems/rake-10.1.0/lib/rake/application.rb:115:in `
run_with_threads'
C:/Ruby200/lib/ruby/gems/2.0.0/gems/rake-10.1.0/lib/rake/application.rb:100:in `
top_level'
C:/Ruby200/lib/ruby/gems/2.0.0/gems/rake-10.1.0/lib/rake/application.rb:78:in `b
lock in run'
C:/Ruby200/lib/ruby/gems/2.0.0/gems/rake-10.1.0/lib/rake/application.rb:165:in `
standard_exception_handling'
C:/Ruby200/lib/ruby/gems/2.0.0/gems/rake-10.1.0/lib/rake/application.rb:75:in `r
un'
C:/Ruby200/lib/ruby/gems/2.0.0/gems/rake-10.1.0/bin/rake:33:in `<top (required)>
'
C:/Ruby200/bin/rake:23:in `load'
C:/Ruby200/bin/rake:23:in `<main>'
Tasks: TOP => db:create => db:load_config

不确定要查找哪个文件的错误:

(<unknown>): did not find expected key while parsing a block mapping at line 11
    column 1

我在过去的几个小时里一直在努力解决这个问题,但找不到解决方案。请指教。谢谢。

4

2 回答 2

1

我通过在普通记事本中打开 yml 文件来提供 root 密码。所以我相信它无法读取密码。然后我通过notepad ++编辑了yml文件,它工作正常。所以似乎我们需要使用 notepad++ 或 editplus 或类似的收费来编辑这些文件。

于 2013-08-04T12:38:04.567 回答
0

看起来您的config\database.yml文件缺少一些数据,它应该类似于以下内容:

development:
  adapter: mysql
  database: my_project_development
  host: localhost
  username: my_user
  password: my_password

您的 gemfile 中还需要一个 mysql gem。

于 2013-08-03T14:01:46.353 回答