第1行第1列不允许使用心理控制字符

时间:2015-05-31 03:34:25

标签: ruby postgresql rake yaml ruby-on-rails-4.2

我正在使用yaml_db gem将我的数据库从PHP / mySQL迁移到RoR / Postgres。我运行时输入YAML文件的第1555870行(约4M)出现上述错误:

bundle exec rake db:data:load RAILS_ENV=production

它似乎与行或大小有关 - 我已将其缩小到这一特定行,目前对此有评论:

-
  slot_id: '2628865'
  sheet_id: '18485'
  label: '10:20am to 12:20pm'
  name: 'Jim Watson'
  email: ''
#bad here - moving "breakrighthere" before this comment throws error related to bad syntax
breakrighthere
-
  slot_id: '2628866'
  sheet_id: '18485'
  label: '2:35pm to 3:05pm'
  name: 'Christy Brown'
  email: ''

堆栈跟踪:

rake aborted!
Psych::SyntaxError: (<unknown>): control characters are not allowed at line 1 column 1
/home/signup/app/releases/11/vendor/bundle/ruby/2.1.0/gems/yaml_db-0.3.0/lib/yaml_db.rb:61:in `load_documents'
/home/signup/app/releases/11/vendor/bundle/ruby/2.1.0/gems/yaml_db-0.3.0/lib/serialization_helper.rb:57:in `block in load'
/home/signup/app/releases/11/vendor/bundle/ruby/2.1.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/abstract/database_statements.rb:213:in `block in transaction'
/home/signup/app/releases/11/vendor/bundle/ruby/2.1.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/abstract/transaction.rb:188:in `within_new_transaction'
/home/signup/app/releases/11/vendor/bundle/ruby/2.1.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/abstract/database_statements.rb:213:in `transaction'
/home/signup/app/releases/11/vendor/bundle/ruby/2.1.0/gems/yaml_db-0.3.0/lib/serialization_helper.rb:56:in `load'
/home/signup/app/releases/11/vendor/bundle/ruby/2.1.0/gems/yaml_db-0.3.0/lib/serialization_helper.rb:31:in `load'
/home/signup/app/releases/11/vendor/bundle/ruby/2.1.0/gems/yaml_db-0.3.0/lib/tasks/yaml_db_tasks.rake:35:in `block (3 levels) in <top (required)>'
Tasks: TOP => db:data:load
(See full trace by running task with --trace)

有什么想法吗?

2 个答案:

答案 0 :(得分:2)

我遇到了同样的错误,并希望能够帮助将来可能会看到此内容的人,最终会出现空白错误。

我在多个应用程序中打开了文件,它改变了选项卡的空间量。

先检查间距!如果最终成为问题,这是最容易解决的问题!

答案 1 :(得分:1)

该错误具有误导性,但您提供的示例是不正确的YAML,并且应该在任何解析器中抛出错误。您可以在一些在线解析器(基于python)中提供文本withwithout注释时轻松检查。

问题是在那条未缩进的行的开头应该有一个破折号(如果破折号不在行的开头,你可以选择在块样式中完成序列)。