Rails initializers are running while migrating database
问题 It is very surprising that Rails's initializers run while running any rake task, including db:migrate and db:seed . An initializer in my app starts a background thread (a kind of worker process), and it should be executed only when the application is running in debug and production mode. How to prevent a specific initializer from running when doing rake db:migrate or how to detect in initializer that a rake task is running? 回答1: Here is a solution how to prevent an initializer from running in