2015-12-15 90 views
0

我正在使用the seed-fu gem,并且能够获得2个文件来成功地为db创建种子。下面的文件,同时在终端产生输出,不填充DB:rake db:seed_fu没有填充数据库

# 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 = "[email protected]" 
    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 

一些背景:

我使用的种子福〜> 2.3, residents.rb生活db/fixtures/内部,轨道版本4.2

预先感谢您的光临!

回答

1

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

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

+0

谢谢Jeiwan,我没有阅读SQL并调用unscoped.all对Resident显示我的记录。 – sirramongabriel