Rake not able to migrate

﹥>﹥吖頭↗ 提交于 2020-01-11 13:21:10

问题


C:\Users\MEGHA\bbbb>rake db:migrate
rake aborted!
SyntaxError: C:/Users/MEGHA/bbbb/db/migrate/20140402130040_create_comments.rb:4: syntax error, unexpected tIDENTIFIER, expecting keyword_end
C:65535:in `disable_ddl_transaction'
Tasks: TOP => db:migrate
(See full trace by running task with --trace)

20140402130040_create_comments.rb

class CreateComments < ActiveRecord::Migration
  def change
    create_table :comments do |t|
      t.string :post_id=integer
      t.text :body

      t.timestamps
    end
  end
end

回答1:


instead:

class CreateComments < ActiveRecord::Migration
  def change
    create_table :comments do |t|
      t.string :post_id=integer #<= this 
      t.text :body

      t.timestamps
    end
  end
end

use

class CreateComments < ActiveRecord::Migration
  def change
    create_table :comments do |t|
      t.integer :post_id
      t.text :body

      t.timestamps
    end
  end
end



回答2:


In your migration you have used

:post_id = integer

Instead it needs to be as below:

 class CreateComments < ActiveRecord::Migration
   def change
 create_table :comments do |t|
    t.integer :post_id
    t.text :body
    t.timestamps
  end
end

end



来源:https://stackoverflow.com/questions/22812513/rake-not-able-to-migrate

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!