Ruby on rails rake db:种子给予验证错误:电子邮件已存在

Ruby on rails rake db:种子给予验证错误:电子邮件已存在,ruby-on-rails,ruby,postgresql,rspec,rake,Ruby On Rails,Ruby,Postgresql,Rspec,Rake,我正在为其中一个项目设立分支机构 在创建数据库I之后: rake db:schema:load 然后 加载种子数据 这会抛出一个错误 雷克流产了!验证失败:Webiso帐户已被删除 已拍摄,电子邮件已拍摄 其中Webiso和电子邮件是其中一个表中的字段 我已经删除、创建并再次加载了模式 我试过流行语。数据库:重置、数据库:设置等 什么都不管用 任何帮助都将不胜感激 db/seeds.rb # This file should contain all the record creation ne

我正在为其中一个项目设立分支机构

在创建数据库I之后:

rake db:schema:load
然后

加载种子数据

这会抛出一个错误

雷克流产了!验证失败:Webiso帐户已被删除 已拍摄,电子邮件已拍摄

其中Webiso和电子邮件是其中一个表中的字段

我已经删除、创建并再次加载了模式

我试过流行语。数据库:重置、数据库:设置等

什么都不管用

任何帮助都将不胜感激

db/seeds.rb

# This file should contain all the record creation needed to seed the database with its default values.
# The data can then be loaded with the rake db:seed (or created alongside the db with db:setup).
#
# Examples:
#
#   cities = City.create([{ :name => 'Chicago' }, { :name => 'Copenhagen' }])
#   Mayor.create(:name => 'Daley', :city => cities.first)


require 'factory_girl'

FactoryGirl.define do
  factory :xx, :parent => :person do
    first_name "xx"
    last_name "xx"
    twiki_name "xx"
    human_name "xx"
    email "xxx@xx"
    is_staff 1

  end


  factory :ed, :parent => :person do
    first_name "Ed"
    last_name "xx"
    twiki_name "xx"
    human_name "xx"
    email "xx@xx"
    is_staff 1
    image_uri "/images/staff/xx.jpg"
  end


  factory :anubhav, :parent => :person do
    is_student 1
    is_part_time 0
    graduation_year "2021"
    masters_program "SE"
    masters_track "Tech"
    twiki_name "AnubhavAeron"
    first_name "Anubhav"
    last_name "Aeron"
    human_name "Anubhav Aeron"
    email "xx@xx"
    webiso_account "x@xx"
  end

end

Factory(:task_type, :name => "Working on deliverables")
Factory(:task_type, :name => "Readings")
Factory(:task_type, :name => "Meetings")
Factory(:task_type, :name => "Other")


xx = Factory.create(:xx)
xx = Factory.create(:xx)
Factory.create(:anubhav)
Factory.create(:team_terrific) #This will create awe_smith, betty_ross, and charlie_moss

FactoryGirl.create(:presentation_feedback_questions, :label => "Content", :text => "Did the talk cover all the content suggested on the checklist? (ie goals, progress, and the process for achieving the goals, outcomes)")
FactoryGirl.create(:presentation_feedback_questions, :label => "Organization", :text => "How logical was the organization? How smooth were transactions between points and parts of the talk?  Was the talk focused? To the point?  Were the main points clearly stated? easy to find?")
FactoryGirl.create(:presentation_feedback_questions, :label => "Visuals", :text => "Were they well-designed? Were all of them readable? Were they helpful? Were they manipulated well?")
FactoryGirl.create(:presentation_feedback_questions, :label => "Delivery", :text => "Bodily delivery: (eye-contact, gestures, energy)    Vocal delivery: (loudness, rate, articulation) Question handling (poise, tact, team support; did the team answer the question asked?)")
这(输入错误?)可能是您错误的原因:

xx = Factory.create(:xx)
xx = Factory.create(:xx)
它将尝试创建两个
Person
实例并将它们保存到数据库中。它们都具有相同的属性(电子邮件),从而触发您的
验证:电子邮件
(或类似)在您的
个人
模型中的唯一性



注意:如果不是输入错误,请查看和/或。

请发布您的
db/seeds.rb
。不是输入错误。当I命令:rake db:schema:load时,I xx只是对原始数据的一种掩盖。事情进展顺利。它加载模式。在rake db上:种子。它抛出验证错误!那封电子邮件已经存在了。如何加载相同的数据两次。您的工厂没有提供(等幂)生成和保存有效的
Person
记录所需的数据(即反复生成相同的电子邮件地址)。只需将Factory Girl序列应用于电子邮件属性。我为每个用户放置了不同的电子邮件ID,因此我不需要序列。为了公开隐藏它,我使用了xxThen,然后提供了一个更好的屏蔽和简洁的
seeds.rb
xx = Factory.create(:xx)
xx = Factory.create(:xx)