Ruby DB迁移错误'rake db:migrate'

时间:2014-07-18 16:23:20

标签: ruby-on-rails ruby ruby-on-rails-4 rubymine

我开始玩ruby并设置我的开发环境。

我正在引用This Ruby on Rails 'Getting Started Guide',并参见第5.5节“运行迁移”

问题是当我运行以下命令时

rake db:migrate

我收到以下错误

C:\Users\someuser\RubymineProjects\my_app>rake db:migrate 
rake aborted!
SyntaxError:C:/Users/someuser/RubymineProjects/my_app/db/migrate/20140718160751_create_articles.rb:4: syntax error, unexpected '[', expecting tSTRING_CONTENT or tSTRING_DBEG or tSTRING_DVAR or tSTRING_END
  t.string :[title
             ^
C:/Users/someuser/RubymineProjects/my_app/db/migrate/20140718160751_create_articles.rb:5: syntax error, unexpected ']', expecting keyword_end
  t.text] :text
         ^
C:in `disable_ddl_transaction'
Tasks: TOP => db:migrate
(See full trace by running task with --trace)

知道造成这种情况的原因以及如何解决这个问题?

1 个答案:

答案 0 :(得分:3)

您的迁移中看起来有一些不属于那里的额外括号。迁移应该如下所示:

class CreateArticles < ActiveRecord::Migration
  def change
    create_table :articles do |t|
      t.string :title
      t.text :text

      t.timestamps
    end
  end
end