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