rake db:seed_fu没有填充数据库

时间:2015-12-15 04:03:15

标签: ruby-on-rails ruby-on-rails-4

我使用the seed-fu gem并且能够获得2个文件以成功播种数据库。以下文件虽然在终端中生成输出,但不填充db:

# residents.rb


Resident.seed do |r|
  r.account_id = 1
  r.employee_id = 1
  r.first_name = "solomon"
  r.last_name = "gibsom"
  r.gender = "Male"
  r.dob = Date.parse("1937-02-20")
  r.case_number = "H-3827-JKZ-0329"
  r.veteran_status_number = "G-15 classified"
  r.marital_status = "Married"
  r.arrival_date = Date.today
  r.religious_preferences = "None"
  r.insurance_info = "Medicaid"
  r.burial_provisions = "Cremation"
  r.admission_weight = "121 lbs"
  r.admission_height = "5ft 9in"
  r.allergies = "Corn, wheat and peanut allergies"
end

Address.seed do |r|
  r.account_id = 1
  r.employee_id = 1
  r.resident_id = 1
  r.street_address = "55298 solomon hills blvd"
  r.city = "Flint"
  r.state = "MI"
  r.zip = "48289"
end

PrimaryPhone.seed do |r|
  r.account_id = 1
  r.employee_id = 1
  r.resident_id = 1
  r.area_code = "810"
  r.number = "565-0255"
end

终端输出:

Terminal output

输出看起来不错,所以我检查控制台中的记录:

Rails console confirms no objects committed

我在进一步寻找错误的地方时感到很茫然。

以下两个文件按预期工作:

#accounts.rb

Account.seed do |a|
  a.facility_name = "Chuck Norris AFC"
end

#admins.rb

Employee.seed do |a|
  a.account_id = 1
  a.is_admin = true
  a.first_name = "kenneth"
  a.last_name = "the paige"
  a.email = "test@example.com"
  a.password = "12345678"
  a.password_confirmation = "12345678"
  a.dob = Date.parse("1965-05-05")
  a.gender = "Male"
end

Address.seed do |address|
  address.account_id = 1
  address.employee_id = 1
  address.street_address = "123 Chuckleburger dr."
  address.city = "New York"
  address.state = "NY"
  address.zip = "00001"
end

一些背景:

我使用seed-fu~> 2.3, residents.rb位于db/fixtures/内,且rails版本为4.2

提前感谢您的光临!

1 个答案:

答案 0 :(得分:1)

运行Resident.all时,请注意控制台中打印的SQL查询:它们的条件为WHERE resident.account_id is NULL。但在种子文件中,Resident有account_id = 1

您可能会为default_scope型号设置Resident。尝试运行Resident.unscoped.all或删除默认范围。