2015-12-15 112 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