db:seed not loading models

后端 未结 3 410
轻奢々
轻奢々 2021-01-18 12:23

I\'m trying to seed my database with the standard db/seeds.rb method. This works fine on my development machine, but on my server, I get:

$ sudo         


        
相关标签:
3条回答
  • 2021-01-18 12:52

    It can be fixed by disabling threadsafe! in the environment configuration.

    0 讨论(0)
  • 2021-01-18 12:54

    In a comment to the blog posted linked to above and here again: http://www.builtfromsource.com/2011/02/09/getting-rake-dbseed-and-config-threadsafe-to-play-nice/

    Bruce Adams mentions that one can call:

    config.threadsafe! unless $rails_rake_task

    to only turn on threadsafe when not running a rake task.

    But as the issue is really that threadsafe turns off dependency_loading, you can simply add this line after config.threadsafe! to leave it enabled, but still load your environment as you expect.

    config.dependency_loading = true if $rails_rake_task

    0 讨论(0)
  • 2021-01-18 13:01

    I just ran across a good approach to this problem in this article. I'll summarize here so people can (hopefully) find it quicker.

    The idea is to turn off threadsafe in the production environment, first by editing config/environments/production.rb:

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

    You then set THREADSAFE=off when running rake tasks.

    0 讨论(0)
提交回复
热议问题