耙不能迁移

时间:2014-04-02 13:08:34

标签: ruby-on-rails ruby rake

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

2 个答案:

答案 0 :(得分:1)

代替:

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

使用

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

      t.timestamps
    end
  end
end

答案 1 :(得分:0)

在您的迁移中,您已使用

  

:post_id = integer

相反,它需要如下所示:

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