seeds.rb中的所有数据都没有加载到开发数据库中。没有错误消息。我该如何确定原因?
如果我运行rake:db:migrate:reset
,它只会运行并且不会产生任何错误消息。如果我去控制台,运行User.first,它说没有。我也下载了开发数据库并且没有记录(表格是正确创建的,只是没有记录)。
有没有办法追查原因? seed.rb的一部分:
User.create!(fullname: "Example User",
username: "fakename0",
email: "example@railstutorial.org",
admin: true,
activated: true,
activated_at: Time.zone.now,
password: "foobar",
password_confirmation: "foobar")
User.create!(fullname: "Example User 2",
username: "fawwkename0",
email: "exaaample@railstutorial.org",
admin: false,
activated: true,
activated_at: Time.zone.now,
password: "foobar",
password_confirmation: "foobar")
99.times do |n|
fullname = Faker::Name.name
username = "fakename#{n+1}"
email = "example-#{n+1}@railstutorial.org"
password = "password"
User.create!(fullname: fullname,
username: username,
email: email,
password: password,
password_confirmation: password,
activated: true,
activated_at: Time.zone.now)
end
Message.create!(email: "example@example.com",
name: "Example User",
content: "This is my message")
Organization.create!(org_name: "Fictious business",
bio: "The background of the organization here",
actioncode: 111)
99.times do |n|
org_name = Faker::Company.name
bio = Faker::Lorem.paragraph(2)
actioncode = Faker::Number.number(3)
Organization.create!(org_name: org_name,
bio: bio,
actioncode: actioncode)
end
Member.create!(organization_id: rand(1..100),
email: "me@example.com",
username: "fake-name0",
fullname: Faker::Name.name,
activated: 1,
activated_at: Time.zone.now,
password: "foobar",
password_confirmation: "foobar")
99.times do |n|
organization_id = rand(1..100)
email = "rails0-#{n+1}@example.com"
username = "fake-name#{n+1}"
fullname = Faker::Name.name
activated = rand(0..1)
activated_at = Faker::Date.backward(14) if activated==1
password = "foobar"
password_confirmation = "foobar"
Member.create!(organization_id: organization_id,
email: email,
username: username,
fullname: fullname,
activated: activated,
activated_at: activated_at,
password: password,
password_confirmation: password_confirmation)
end
答案 0 :(得分:0)
要加载db / seeds.rb,您需要运行rake db:seed
。