本文介绍了解析C:/Users/Vanessa/rails_space/config/database.yml时发生YAML语法错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我在命令提示符下输入以下代码时:

When I enter this code into my command prompt:

  rails g model User

这是我在控制台中看到的内容:

Here is what I get in the console:

  YAML syntax error occurred while parsing 
  C:/Users/Vanessa/rails_space/config/database.yml. Please note that YAML 
  must be consistently indented using spaces. Tabs are not allowed. Error: 
  (<unknown>): did not find expected key while parsing a block mapping at 
  line 7 column 1 (RuntimeError)

这是我的config/database.yml文件中的代码:

Here is the code from my config/database.yml file:

    # SQLite. Versions 3.8.0 and up are supported.
#   gem install sqlite3
#
#   Ensure the SQLite 3 gem is defined in your Gemfile
#   gem 'sqlite3'
#
default: &default
  adapter: sqlite3
  pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
  timeout: 5000

development:
   adapter: mysql
  database: rails_space_development
  username: root
  password: NothingToSeeHere
  host: localhost

  <<: *default
  database: db/development.sqlite3

# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
  <<: *default
  database: db/test.sqlite3

production:
  <<: *default
  database: db/production.sqlite3

推荐答案

在您的开发密钥下,对于适配器,您似乎有一个间距错误.尝试将其更改为:

It looks like, under your development key, for adapter, you have a spacing error. Try changing it to:

development:
  adapter: mysql

adapter之前的空格太多.

YAML关于间距非常具体.如您所知,甚至一个多余的空间也会引发错误.并且必须确保使用空格,而不是制表符.

YAML is very specific about spacing. As you've found out, even one extra space throws an error. And you have to make sure you use spaces, not tabs.

这篇关于解析C:/Users/Vanessa/rails_space/config/database.yml时发生YAML语法错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-01 02:25