0
当我用pry在控制台中调试时,我运行了brief = Factory(:brief,:project => Factory(:project))这个命令。它应该是工作的,但是我得到了这个错误。factorygirl创建错误
ActiveRecord::RecordNotUnique: PG::Error: ERROR: duplicate key value violates unique constraint "index_briefs_on_project_id"
DETAIL: Key (project_id)=(15389) already exists.
: INSERT INTO "briefs" ("project_id", "duration", "brand_name", "brand_info",
"customer_info", "competitor_info", "desired_impression", "competencies", "preferences",
"examples", "notes", "created_at", "updated_at", "channel_id") VALUES (15389, 14, NULL,
'brand info', NULL, NULL, NULL, NULL, NULL, NULL, NULL,
'2013-04-06 01:07:04.717364', '2013-04-06 01:07:04.717364', NULL) RETURNING "id"
为什么会发生此错误,我该如何解决?
编辑:我加了我厂的文件
brief_factory.rb
Factory.define :brief, :class => Brief do |b|
b.brand_info 'brand info'
b.duration 14
end
project_factory.rb
Factory.define :project, :class => Project do |p|
p.association :owner, :factory => :customer
p.title 'project title'
p.description 'project description'
p.stage :brief_completed
p.contest_type :standard
p.brief Factory.build(:brief)
p.association :project_type, :factory => :project_type
end
请添加您的工厂定义代码的问题。 – 2013-04-06 01:20:21
我添加了工厂文件。 – 2013-04-06 01:28:26