Rails自动生成的迁移导致语法错误,意外的' \ n'""错误

时间:2016-06-29 21:15:28

标签: database postgresql ruby-on-rails-4 migration

我正在使用Rails 4.2.3。我创建了这个迁移,它是由Rails自动生成的......

class CreateDistanceUnits < ActiveRecord::Migration
  def change
    create_table :distance_units do |t|
      t.string, :description
      t.string :abbrev
      t.timestamps null: false
    end
    add_index :distance_units, [:abbrev], :unique => true
  end
end

但是当我运行它时,我得到了这个奇怪的错误

davea$ rake db:migrate
rake aborted!
SyntaxError: /Users/davea/Documents/workspace/runtrax/db/migrate/20160629210722_create_distance_units.rb:4: syntax error, unexpected '\n', expecting &. or :: or '[' or '.'
/Users/davea/.rvm/gems/ruby-2.3.0@global/gems/activesupport-4.2.5.1/lib/active_support/dependencies.rb:244:in `rescue in load_dependency'
/Users/davea/.rvm/gems/ruby-2.3.0@global/gems/activesupport-4.2.5.1/lib/active_support/dependencies.rb:237:in `load_dependency'
/Users/davea/.rvm/gems/ruby-2.3.0@global/gems/activesupport-4.2.5.1/lib/active_support/dependencies.rb:274:in `require'
/Users/davea/.rvm/gems/ruby-2.3.0@global/gems/activerecord-4.2.5.1/lib/active_record/migration.rb:777:in `load_migration'
/Users/davea/.rvm/gems/ruby-2.3.0@global/gems/activerecord-4.2.5.1/lib/active_record/migration.rb:773:in `migration'
/Users/davea/.rvm/gems/ruby-2.3.0@global/gems/activerecord-4.2.5.1/lib/active_record/migration.rb:768:in `disable_ddl_transaction'
/Users/davea/.rvm/gems/ruby-2.3.0@global/gems/activerecord-4.2.5.1/lib/active_record/migration.rb:1051:in `use_transaction?'
/Users/davea/.rvm/gems/ruby-2.3.0@global/gems/activerecord-4.2.5.1/lib/active_record/migration.rb:1043:in `ddl_transaction'
/Users/davea/.rvm/gems/ruby-2.3.0@global/gems/activerecord-4.2.5.1/lib/active_record/migration.rb:997:in `execute_migration_in_transaction'
/Users/davea/.rvm/gems/ruby-2.3.0@global/gems/activerecord-4.2.5.1/lib/active_record/migration.rb:959:in `block in migrate'
/Users/davea/.rvm/gems/ruby-2.3.0@global/gems/activerecord-4.2.5.1/lib/active_record/migration.rb:955:in `each'
/Users/davea/.rvm/gems/ruby-2.3.0@global/gems/activerecord-4.2.5.1/lib/active_record/migration.rb:955:in `migrate'
/Users/davea/.rvm/gems/ruby-2.3.0@global/gems/activerecord-4.2.5.1/lib/active_record/migration.rb:823:in `up'
/Users/davea/.rvm/gems/ruby-2.3.0@global/gems/activerecord-4.2.5.1/lib/active_record/migration.rb:801:in `migrate'
/Users/davea/.rvm/gems/ruby-2.3.0@global/gems/activerecord-4.2.5.1/lib/active_record/tasks/database_tasks.rb:137:in `migrate'
/Users/davea/.rvm/gems/ruby-2.3.0@global/gems/activerecord-4.2.5.1/lib/active_record/railties/databases.rake:44:in `block (2 levels) in <top (required)>'
/Users/davea/.rvm/gems/ruby-2.3.0/gems/rake-11.2.2/exe/rake:27:in `<top (required)>'
/Users/davea/.rvm/gems/ruby-2.3.0/bin/ruby_executable_hooks:15:in `eval'
/Users/davea/.rvm/gems/ruby-2.3.0/bin/ruby_executable_hooks:15:in `<main>'

抱怨什么?我正在使用PostGres数据库。谢谢, - 戴夫

1 个答案:

答案 0 :(得分:0)

尝试此操作

class CreateDistanceUnits < ActiveRecord::Migration
  def change
    create_table :distance_units do |t|
      t.string :description
      t.string :abbrev
      t.timestamps null: false
    end
    add_index :distance_units, [:abbrev], :unique => true
  end
end

,

之前迁移中出现意外:description