0

我正在尝试创建此 Rails 迁移

class CreateFormats < ActiveRecord::Migration
  def self.up
    create_table (:formats , :options => 'ENGINE=InnoDB DEFAULT CHARSET=utf8' ) do |t|
      t.name
      t.description 
      t.company

      t.timestamps
    end
  end

  def self.down
    drop_table :formats
  end
end

我在执行过程中遇到如下错误:

语法错误,意外 ',',期待 ')' create_table (:formats , :options => 'ENGINE=InnoDB D... ^ 语法错误,意外')',期待 keyword_end ...=InnoDB DEFAULT CHARSET=utf8' ) 做 |t| ... ^

语法错误,意外的keyword_end,期待$end

知道为什么会这样吗?我的语法找不到任何问题..很可能是因为我是 Rails 新手 :)

4

1 回答 1

2

您的语法不正确:

create_table (:formats , :options => 'ENGINE=InnoDB DEFAULT CHARSET=utf8' ) do |t|

应该

create_table(:formats , :options => 'ENGINE=InnoDB DEFAULT CHARSET=utf8' ) do |t|

即:没有空间。否则,您只是将:formatswith:options => ...作为函数的第一个参数进行分组。

你可能还需要改变

t.name
t.description 
t.company

类似于

t.string :name
t.string :description 
t.string :company
于 2011-05-25T22:06:01.587 回答