我运行了以下命令:
rails generate scaffold order name:string address:text email:string pay_type:string
rails generate migration add_order_id_to_line_item order_id:integer
rake db:migrate
由于某种原因,db / schema.db不显示orders表。我甚至尝试将它手动放在schema.db中并再次迁移,但我仍然无法访问/命令:(
任何人都知道可能导致这种情况的原因是什么?
网页访问错误:http://i.imgur.com/5OpZP.jpg
移民输出:http://i.imgur.com/5OEsw.jpg
答案 0 :(得分:2)
您的迁移文件20110623001141_combine_items_in_cart.rb没有正确的类包装器,此外它内部的方法也不应该存在。
class CombineItemsInCart < ActiveRecord::Migration
def self.up
# replace multiple items for a single product in a cart with a single item
Cart.all.each do |cart|
# count the number of each product in the cart
sums = cart.line_items.group(:product_id).sum(:quantity)
sums.each do |product_id, quantity|
if quantity >1
# remove individual items
cart.line_items.where(:product_id=>product_id).delete_all
# replace with a single item
cart.line_items.create(:product_id=>product_id, :quantity=>quantity)
end
end
end
end
def self.down
# split items with quantity>1 into multiple items
LineItem.where("quantity>1").each do |line_item|
# add individual items
line_item.quantity.times do
LineItem.create :cart_id=>line_item.cart_id,
:product_id=>line_item.product_id, :quantity=>1
end
# remove original item
line_item.destroy
end``
end
end
您似乎在20110626203934_add_oder_to_line_item.rb中有一个副本,它正在添加一个已由20110626181924_add_order_id_to_line_item.rb添加的列。删除其中任何一个并再次尝试迁移。