rake db:seed给出验证错误:电子邮件已存在

时间:2014-05-03 14:55:40

标签: ruby-on-rails ruby postgresql rspec rake

我正在其中一个项目上设置一个分叉。

创建数据库后我:

rake db:schema:load

然后

rake db:seed

加载种子数据。

这会抛出错误

  耙子流产了!验证失败:Webiso帐户已经存在   已经采取了电子邮件

Webiso和Email是其中一个表中的字段。

我已经删除,重新创建并加载了架构。

我试过流行语。 db:reset,db:setup等。

没有任何作用。

任何帮助都将不胜感激。

分贝/ 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?)")

1 个答案:

答案 0 :(得分:0)

这(错误?)可能是导致错误的原因:

xx = Factory.create(:xx)
xx = Factory.create(:xx)

将尝试创建两个Person实例并将其保存到数据库中。它们都共享相同的属性(电子邮件),触发validates_uniqueness_of :email模型中的Person(或类似)验证。


N.B。如果不是拼写错误,请查看sequences和/或Faker