【发布时间】:2012-04-16 17:25:44
【问题描述】:
我正在尝试为我的 rails 3 应用程序播种,但遇到了问题。我的类别表有以下字段:
字符串“名称” 整数“位置” 整数“parent_id”
parent_id 是另一个类别的 id,用于nested_set。
种子.rb
Category.delete_all
Category.create(:name => "Category 1",
:position => 1,
:parent_id => nil )
Category.create(:name => "Subcategory 1",
:position => 1,
:parent_id => 1 )
当我跑步时
rake db:seed
我得到错误:
rake aborted!
Couldn't find Category with id=1
Tasks: TOP => db:seed
(See full trace by running task with --trace)
那么,如何首先创建类别,以便 ID 1 可用?
【问题讨论】:
标签: ruby-on-rails activerecord rake nested-sets seed