【问题标题】:Rake not able to migrateRake 无法迁移
【发布时间】:2014-04-02 13:08:33
【问题描述】:
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_cmets.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

【问题讨论】:

  • NOT able to rake db:migrate 的可能重复项。提问者,我已投票结束这个问题,因为它与你接受答案的问题重复。今后,请不要多次发布相同的问题。

标签: ruby-on-rails ruby rake


【解决方案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

【讨论】:

    【解决方案2】:

    在你的迁移中你使用过

    :post_id = 整数

    相反,它需要如下:

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

    结束

    【讨论】:

      猜你喜欢
      • 2014-05-13
      • 1970-01-01
      • 2014-06-14
      • 2013-06-28
      • 2013-02-01
      • 2011-08-19
      • 2012-08-27
      • 2012-11-17
      • 1970-01-01
      相关资源
      最近更新 更多