db:种子不加载模型

我正在尝试使用标准db/seeds.rb方法为我的数据库设定种子。 这在我的开发机器上工作正常,但在我的服务器上,我得到:

 $ sudo rake db:seed RAILS_ENV=production --trace ** Invoke db:seed (first_time) ** Invoke environment (first_time) ** Execute environment ** Execute db:seed rake aborted! uninitialized constant Permission /usr/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2503:in `const_missing' /usr/local/lib/ruby/gems/1.8/gems/activesupport-2.3.4/lib/active_support/dependencies.rb:92:in `const_missing' /path/.../.../.../.../db/seeds.rb:4 /usr/local/lib/ruby/gems/1.8/gems/rails-2.3.4/lib/tasks/databases.rake:215:in `load' /usr/local/lib/ruby/gems/1.8/gems/rails-2.3.4/lib/tasks/databases.rake:215 /usr/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:636:in `call' ... 

但是当我在控制台中检查时,模型确实存在:

 $ script/console production Loading production environment (Rails 2.3.4) >> Permission => Permission(id: integer, ..., created_at: datetime, updated_at: datetime) 

我忘记了什么?

在上面和此处链接的博客评论中再次发布: http : //www.builtfromsource.com/2011/02/09/getting-rake-dbseed-and-config-threadsafe-to-play-nice/

布鲁斯亚当斯提到可以打电话:

config.threadsafe! 除非$ rails_rake_task

仅在不运行rake任务时打开线程安全。

但是因为问题确实是线程安全关闭依赖性加载,你可以在config.threadsafe之后添加这一行! 保持启用状态,但仍按预期加载环境。

config.dependency_loading =如果是$ rails_rake_task则为true

它可以通过禁用threadsafe!来修复threadsafe! 在环境配置中。

我刚刚在本文中遇到了解决此问题的方法。 我将在这里总结,以便人们可以(希望)更快地找到它。

想法是在生产环境中关闭线程安全,首先编辑config / environments / production.rb:

 config.threadsafe! unless ENV['THREADSAFE'] == 'off' 

然后在运行rake任务时设置THREADSAFE = off。