I want to seed the database with Faker, the problem is that I am getting an error when I do a:
我想用Faker为数据库播种,问题是当我这样做时出现错误:
rake db:reset
I get this message:
我收到这条消息:
rake aborted!
I18n::MissingTranslationData: translation missing: en.faker.name.name
/Library/Ruby/Gems/2.0.0/gems/i18n-0.7.0/lib/i18n.rb:311:in `handle_exception'
/Library/Ruby/Gems/2.0.0/gems/i18n-0.7.0/lib/i18n.rb:161:in `translate'
/Library/Ruby/Gems/2.0.0/gems/faker-1.4.3/lib/faker.rb:128:in `rescue in translate'
/Library/Ruby/Gems/2.0.0/gems/faker-1.4.3/lib/faker.rb:120:in `translate'
/Library/Ruby/Gems/2.0.0/gems/faker-1.4.3/lib/faker.rb:86:in `fetch'
/Library/Ruby/Gems/2.0.0/gems/faker-1.4.3/lib/faker.rb:99:in `parse'
/Library/Ruby/Gems/2.0.0/gems/faker-1.4.3/lib/faker/name.rb:8:in `name'
/Users/hbendev/code/wikitec/db/seeds.rb:6:in `block in <top (required)>'
/Users/hbendev/code/wikitec/db/seeds.rb:4:in `times'
/Users/hbendev/code/wikitec/db/seeds.rb:4:in `<top (required)>'
/Library/Ruby/Gems/2.0.0/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:268:in `load'
/Library/Ruby/Gems/2.0.0/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:268:in `block in load'
/Library/Ruby/Gems/2.0.0/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:240:in `load_dependency'
/Library/Ruby/Gems/2.0.0/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:268:in `load'
/Library/Ruby/Gems/2.0.0/gems/railties-4.2.0/lib/rails/engine.rb:547:in `load_seed'
/Library/Ruby/Gems/2.0.0/gems/activerecord-4.2.0/lib/active_record/tasks/database_tasks.rb:250:in `load_seed'
/Library/Ruby/Gems/2.0.0/gems/activerecord-4.2.0/lib/active_record/railties/databases.rake:180:in `block (2 levels) in <top (required)>'
/Library/Ruby/Gems/2.0.0/gems/activerecord-4.2.0/lib/active_record/railties/databases.rake:139:in `block (2 levels) in <top (required)>'
Tasks: TOP => db:setup => db:seed
I don't know why is that error appearing, since I haven't got any problems with Faker before, I just wanted to reset the db to update the seeds.
我不知道为什么会出现这个错误,因为我以前没有遇到过Faker的任何问题,我只是想重置数据库以更新种子。
I google it but I can't find anything related that solves the problem.
我谷歌它,但我找不到任何相关的解决问题。
I tried to add:
我试着添加:
I18n.reload!
After require 'faker'
in my seeds.rb file, but no luck.
在我的seeds.rb文件中要求'faker'后,但没有运气。
Looks like the problem is with Faker itself, because the database is being created properly, when I do a rake db:drop db:create db:migrate
it works, until there, but when I try to seed the database with Faker with rake db:seed
or rake db:reset
, I get the error.
看起来问题出在Faker本身,因为数据库正在正确创建,当我做一个rake db:drop db:create db:migrate它工作,直到那里,但是当我尝试使用rake db为Faker播种数据库时:seed或rake db:reset,我收到错误。
What can I do? Thanks in advance.
我能做什么?提前致谢。
UPDATE - I included seeds.rb and en.yml files
更新 - 我包括seeds.rb和en.yml文件
seeds.rb:
require 'faker'
# Create Users
5.times do
user = User.new(
name: Faker::Name.name,
email: Faker::Internet.email,
password: Faker::Lorem.characters(10)
)
user.skip_confirmation!
user.save!
end
users = User.all
# Create Wikis
25.times do
Wiki.create!(
title: Faker::Lorem.sentence,
body: Faker::Lorem.paragraph,
:private => false,
user: users.sample
)
end
# Create Admin account
admin = User.new(
name: 'Admin User',
email: 'admin@example.com',
password: 'helloworld',
role: 'admin'
)
admin.skip_confirmation!
admin.save!
# Create Premium account
premium = User.new(
name: 'Premium User',
email: 'premium@example.com',
password: 'helloworld',
role: 'premium'
)
premium.skip_confirmation!
premium.save!
# Create Standard account
standard = User.new(
name: 'Standard User',
email: 'standard@example.com',
password: 'helloworld',
role: 'standard'
)
standard.skip_confirmation!
standard.save!
puts "Seed finished"
puts "#{Wiki.count} wikis created"
puts "#{User.count} users created"
en.yml:
en:
hello: "Hello world"
3 个解决方案
#1
Check the I18n Faker configuration info here:
在此查看I18n Faker配置信息:
https://github.com/stympy/faker#customization
Looks like you should enforce the I18n Faker locale in case you are using a non standard locale in your app.
看起来您应该强制执行I18n Faker区域设置,以防您在应用中使用非标准区域设置。
Just set Faker::Config.locale to the locale you want, and Faker will take care of the rest.
只需将Faker :: Config.locale设置为您想要的语言环境,Faker将负责其余部分。
#2
This worked for me...
这对我有用......
In your Gemfile
add :require => false
在您的Gemfile中添加:require => false
group :development, :test do
#gem 'faker', '~> 1.4.3'
gem 'faker', :require => false
end
Add require "faker"
manually...
手动添加需要“faker”...
#3
I had the same problem. it is necessary to move faker to Gemfile from
我有同样的问题。有必要将faker移动到Gemfile
group: development: test do
gem 'faker'
end
for me it solved a problem good luck
对我来说它解决了一个问题好运
#1
Check the I18n Faker configuration info here:
在此查看I18n Faker配置信息:
https://github.com/stympy/faker#customization
Looks like you should enforce the I18n Faker locale in case you are using a non standard locale in your app.
看起来您应该强制执行I18n Faker区域设置,以防您在应用中使用非标准区域设置。
Just set Faker::Config.locale to the locale you want, and Faker will take care of the rest.
只需将Faker :: Config.locale设置为您想要的语言环境,Faker将负责其余部分。
#2
This worked for me...
这对我有用......
In your Gemfile
add :require => false
在您的Gemfile中添加:require => false
group :development, :test do
#gem 'faker', '~> 1.4.3'
gem 'faker', :require => false
end
Add require "faker"
manually...
手动添加需要“faker”...
#3
I had the same problem. it is necessary to move faker to Gemfile from
我有同样的问题。有必要将faker移动到Gemfile
group: development: test do
gem 'faker'
end
for me it solved a problem good luck
对我来说它解决了一个问题好运