0
alex@alex-ThinkPad-T410:~/rails_projects/final$ rake db:migrate
rake aborted!
/home/alex/rails_projects/final/db/migrate/20120813025503_add_price_location_and_product_to_microposts.rb:3: syntax error, unexpected ':', expecting ';' or '\n'
    add_column :microposts, :price, :text # d...
                ^
/home/alex/rails_projects/final/db/migrate/20120813025503_add_price_location_and_product_to_microposts.rb:3: syntax error, unexpected ',', expecting tCOLON2 or '[' or '.'
...add_column :microposts, :price, :text # dont forget to chang...
...                               ^
/home/alex/rails_projects/final/db/migrate/20120813025503_add_price_location_and_product_to_microposts.rb:7: syntax error, unexpected keyword_end, expecting $end

这就是错误。这是迁移(下)

class AddPriceLocationAndProductToMicroposts < ActiveRecord::Migration
  def 
    add_column :microposts, :price, :text 
    add_column :microposts, :location, :text
    add_column :microposts, :product, :text
  end
end

我是考虑到这一点而写的http://guides.rubyonrails.org/migrations.html#chang-migrations教派。2.2

为什么要分号?我正在尝试将价格、位置、产品列添加到 microposts 表

4

1 回答 1

2

您必须在前面写上方法名称def

即更改defdef change

class AddPriceLocationAndProductToMicroposts < ActiveRecord::Migration
  def change
    add_column :microposts, :price, :text 
    add_column :microposts, :location, :text
    add_column :microposts, :product, :text
  end
end
于 2012-08-13T05:17:19.587 回答