【发布时间】:2019-08-29 19:40:22
【问题描述】:
我有一个带有 3 个模型的 rails 应用程序,OrderItem、Photo 和 PhotoSize
来自 schema.rb,这是我的表 order_item(我在这里删除了不相关的列):
create_table "order_items", force: :cascade do |t|
t.integer "order_id"
t.integer "photo_size_id"
t.integer "photo_id"
t.index ["order_id"], name: "index_order_items_on_order_id"
t.index ["photo_id"], name: "index_order_items_on_photo_id"
t.index ["photo_size_id"], name: "index_order_items_on_photo_size_id"
end
生成的夹具文件如下所示:
one:
order: one
photo_size: one
photo: one
two:
order: two
photo_size: two
photo: two
现在运行我的测试我得到了错误
ActiveRecord::Fixture::FixtureError: 表“order_items”没有列 命名为“photo_size”。
现在在夹具中使用photo 并在表格中使用相应的photo_id 可以正常工作。 photo_size 及其对应的 photo_size_id 会引发错误。任何人都可以解释这种差异,如何解决这个问题?
我尝试了建议here 添加关于如何将 photo_size 复数的语句,但这并没有解决问题。不过,注释掉夹具文件会自然地停止错误。
【问题讨论】:
标签: ruby-on-rails ruby-on-rails-5