Topic: rake db:migrate works, rake RAILS_ENV=production db:migrate does not..

WTF!

First time deploying...

Setup includes Slicehost, Passenger, and Capistrano

Now... for some strange reason... rake db:migrate works without a hitch...

However, running rake RAILS_ENV=production db:migrate aborts with the following error:

rake aborted!
Mysql::Error: Table 'db_production.posts' doesn't exist: SHOW FIELDS FROM `posts`

Why is it looking for the posts table?? There are no tables yet, as I've not been able to migrate the prod db...

Just had a thought... I'm going to copy the ev db as a temp fix, but why is this the case?

Sheared for the last 2 days, to no avail.

Thanks in advance!

Re: rake db:migrate works, rake RAILS_ENV=production db:migrate does not..

I think it's that your command should be rake db:migrate RAILS_ENV=production

Re: rake db:migrate works, rake RAILS_ENV=production db:migrate does not..

You probably forgot to do: rake db:create:all.

But anyway, read the first lines of schema.rb, for the first time on a production environment you should use: rake db:schema:load

Re: rake db:migrate works, rake RAILS_ENV=production db:migrate does not..

What version of Rails?  this kinda thing used to happen with validates_uniqueness_of in older versions...

Rob Anderton
TheWebFellas

Re: rake db:migrate works, rake RAILS_ENV=production db:migrate does not..

Using Rails 2.2.2


"rake db:schema:load" has the same effect.


"rake db:migrate RAILS_ENV=production" didn't work either, and I don't think the placement matters, it seems from my googling.


"rake db:create:all" - for some reason, doesn't seem to work, I had to create the MYSQL DBs manually.


I should have tried "rake db:migrate RAILS_ENV=development" to ensure it's not the RAILS_ENV option. But it's just odd "rake db:migrate" worked fine.

Thanks for the responses guys. I just imported the dev db, everything is peachy for now...

Re: rake db:migrate works, rake RAILS_ENV=production db:migrate does not..

Same here.

Rails 2.2.2, Ubuntu 8.10 (local and server), Apache 2.2, Passenger 2.0.6, MySQL 5. No Capistrano though, just plain old FTP.

Uploaded files, SSH'd into it, ran 'export RAILS_ENV=production'

And then any of these would yield the same error on rake:

db:drop / db:create / db:reset / db:create:all / db:schema:load

The error was exactly the same as Omarvelous', only with a different table name. It was trying to 'SHOW FIELDS' on a table that obviously does not exist.

I checked for validates_uniqueness_of as rob suggested, but there was none on the model whose table was mentioned on the error.

I ended up setting the environment to development, changing the DB name to the production one, and running (blissfully) db:schema:load. After that I can get back into production and run db:reset, db:schema:load, etc without issues.

Clues anyone?

Re: rake db:migrate works, rake RAILS_ENV=production db:migrate does not..

Might be worth running the rake task with the --trace option and posting the resulting stack trace, might yield some clues.

Rob Anderton
TheWebFellas

Re: rake db:migrate works, rake RAILS_ENV=production db:migrate does not..

Thank you very much sir! I should have done that before anything. Allowed me to pinpoint the problem in like 3 sec. Shame I didn't know the option, and didn't think of looking for it on help.

The culprit seems to be active_scaffold, which is trying to read my schema when these rake tasks run (hence the "SHOW FIELDS"). If I comment the "active_scaffold :model" from my admin controllers all rake tasks run fine.

Now I'd really like to understand what's going on here. WTF controllers have to do with rake tasks concerning database drop/create etc? Granted, active_scaffold does a lot of voodoo to achieve its amazing results but even so in my humble ignorance I'm puzzled by this connection.

Here goes the trace anyway, for anyone who might be interested:

rake db:reset --trace
(in /files/projects/cdp)
** Invoke db:reset (first_time)
** Invoke db:drop (first_time)
** Invoke environment (first_time)
** Execute environment
rake aborted!
Mysql::Error: Table 'cdp_production.answers' doesn't exist: SHOW FIELDS FROM `answers`
/usr/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active_record/connection_adapters/abstract_adapter.rb:188:in `log'
/usr/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active_record/connection_adapters/mysql_adapter.rb:309:in `execute'
/usr/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active_record/connection_adapters/mysql_adapter.rb:440:in `columns'
/usr/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active_record/base.rb:1220:in `columns'
/files/projects/cdp/vendor/plugins/active_scaffold/lib/active_scaffold/config/core.rb:100:in `initialize'
/files/projects/cdp/vendor/plugins/active_scaffold/lib/active_scaffold.rb:56:in `new'
/files/projects/cdp/vendor/plugins/active_scaffold/lib/active_scaffold.rb:56:in `active_scaffold'
/files/projects/cdp/app/controllers/admin/answers_controller.rb:3
/usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
/usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'
/usr/lib/ruby/gems/1.8/gems/activesupport-2.2.2/lib/active_support/dependencies.rb:155:in `require'
/usr/lib/ruby/gems/1.8/gems/activesupport-2.2.2/lib/active_support/dependencies.rb:262:in `require_or_load'
/usr/lib/ruby/gems/1.8/gems/activesupport-2.2.2/lib/active_support/dependencies.rb:221:in `depend_on'
/usr/lib/ruby/gems/1.8/gems/activesupport-2.2.2/lib/active_support/dependencies.rb:133:in `require_dependency'
/usr/lib/ruby/gems/1.8/gems/rails-2.2.2/lib/initializer.rb:368:in `load_application_classes'
/usr/lib/ruby/gems/1.8/gems/rails-2.2.2/lib/initializer.rb:367:in `each'
/usr/lib/ruby/gems/1.8/gems/rails-2.2.2/lib/initializer.rb:367:in `load_application_classes'
/usr/lib/ruby/gems/1.8/gems/rails-2.2.2/lib/initializer.rb:365:in `each'
/usr/lib/ruby/gems/1.8/gems/rails-2.2.2/lib/initializer.rb:365:in `load_application_classes'
/usr/lib/ruby/gems/1.8/gems/rails-2.2.2/lib/initializer.rb:185:in `process'
/usr/lib/ruby/gems/1.8/gems/rails-2.2.2/lib/initializer.rb:112:in `send'
/usr/lib/ruby/gems/1.8/gems/rails-2.2.2/lib/initializer.rb:112:in `run'
/files/projects/cdp/config/environment.rb:13
/usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
/usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'
/usr/lib/ruby/gems/1.8/gems/activesupport-2.2.2/lib/active_support/dependencies.rb:153:in `require'
/usr/lib/ruby/gems/1.8/gems/activesupport-2.2.2/lib/active_support/dependencies.rb:521:in `new_constants_in'
/usr/lib/ruby/gems/1.8/gems/activesupport-2.2.2/lib/active_support/dependencies.rb:153:in `require'
/usr/lib/ruby/gems/1.8/gems/rails-2.2.2/lib/tasks/misc.rake:3
/usr/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake.rb:617:in `call'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake.rb:617:in `execute'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake.rb:612:in `each'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake.rb:612:in `execute'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake.rb:578:in `invoke_with_call_chain'
/usr/lib/ruby/1.8/monitor.rb:242:in `synchronize'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake.rb:571:in `invoke_with_call_chain'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake.rb:588:in `invoke_prerequisites'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake.rb:585:in `each'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake.rb:585:in `invoke_prerequisites'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake.rb:577:in `invoke_with_call_chain'
/usr/lib/ruby/1.8/monitor.rb:242:in `synchronize'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake.rb:571:in `invoke_with_call_chain'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake.rb:588:in `invoke_prerequisites'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake.rb:585:in `each'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake.rb:585:in `invoke_prerequisites'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake.rb:577:in `invoke_with_call_chain'
/usr/lib/ruby/1.8/monitor.rb:242:in `synchronize'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake.rb:571:in `invoke_with_call_chain'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake.rb:564:in `invoke'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake.rb:2019:in `invoke_task'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake.rb:1997:in `top_level'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake.rb:1997:in `each'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake.rb:1997:in `top_level'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake.rb:2036:in `standard_exception_handling'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake.rb:1991:in `top_level'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake.rb:1970:in `run'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake.rb:2036:in `standard_exception_handling'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake.rb:1967:in `run'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.3/bin/rake:31
/usr/bin/rake:19:in `load'
/usr/bin/rake:19

Re: rake db:migrate works, rake RAILS_ENV=production db:migrate does not..

I'm having a similar problem

I'm trying to deploy an application on my staging server but whenever I run rake db:migrate RAILS_ENV=production I get the following error:

** Invoke db:migrate (first_time)
** Invoke environment (first_time)
** Execute environment
rake aborted!
no such file to load -- application
/usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
/usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'
/usr/lib/ruby/gems/1.8/gems/activesupport-2.2.2/lib/active_support/dependencies.rb:155:in `require'
/usr/lib/ruby/gems/1.8/gems/activesupport-2.2.2/lib/active_support/dependencies.rb:262:in `require_or_load'
/usr/lib/ruby/gems/1.8/gems/activesupport-2.2.2/lib/active_support/dependencies.rb:221:in `depend_on'
/usr/lib/ruby/gems/1.8/gems/activesupport-2.2.2/lib/active_support/dependencies.rb:133:in `require_dependency'
/usr/lib/ruby/gems/1.8/gems/actionpack-2.2.2/lib/action_controller/dispatcher.rb:18:in `define_dispatcher_callbacks'
/usr/lib/ruby/gems/1.8/gems/activesupport-2.2.2/lib/active_support/callbacks.rb:182:in `call'
/usr/lib/ruby/gems/1.8/gems/activesupport-2.2.2/lib/active_support/callbacks.rb:182:in `evaluate_method'
/usr/lib/ruby/gems/1.8/gems/activesupport-2.2.2/lib/active_support/callbacks.rb:166:in `call'
/usr/lib/ruby/gems/1.8/gems/activesupport-2.2.2/lib/active_support/callbacks.rb:90:in `run'
/usr/lib/ruby/gems/1.8/gems/activesupport-2.2.2/lib/active_support/callbacks.rb:90:in `each'
/usr/lib/ruby/gems/1.8/gems/activesupport-2.2.2/lib/active_support/callbacks.rb:90:in `send'
/usr/lib/ruby/gems/1.8/gems/activesupport-2.2.2/lib/active_support/callbacks.rb:90:in `run'
/usr/lib/ruby/gems/1.8/gems/activesupport-2.2.2/lib/active_support/callbacks.rb:277:in `run_callbacks'
/usr/lib/ruby/gems/1.8/gems/rails-2.2.2/lib/initializer.rb:559:in `send'
/usr/lib/ruby/gems/1.8/gems/rails-2.2.2/lib/initializer.rb:559:in `prepare_dispatcher'
/usr/lib/ruby/gems/1.8/gems/rails-2.2.2/lib/initializer.rb:173:in `process'
/usr/lib/ruby/gems/1.8/gems/rails-2.2.2/lib/initializer.rb:112:in `send'
/usr/lib/ruby/gems/1.8/gems/rails-2.2.2/lib/initializer.rb:112:in `run'
/home/aspectgroup/aspectexhibition.co.uk/exhibition/config/environment.rb:13
/usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
/usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'
/usr/lib/ruby/gems/1.8/gems/activesupport-2.2.2/lib/active_support/dependencies.rb:153:in `require'
/usr/lib/ruby/gems/1.8/gems/activesupport-2.2.2/lib/active_support/dependencies.rb:521:in `new_constants_in'
/usr/lib/ruby/gems/1.8/gems/activesupport-2.2.2/lib/active_support/dependencies.rb:153:in `require'
/usr/lib/ruby/gems/1.8/gems/rails-2.2.2/lib/tasks/misc.rake:3
/home/aspectgroup/.gem/ruby/1.8/gems/rake-0.8.3/lib/rake.rb:617:in `call'
/home/aspectgroup/.gem/ruby/1.8/gems/rake-0.8.3/lib/rake.rb:617:in `execute'
/home/aspectgroup/.gem/ruby/1.8/gems/rake-0.8.3/lib/rake.rb:612:in `each'
/home/aspectgroup/.gem/ruby/1.8/gems/rake-0.8.3/lib/rake.rb:612:in `execute'
/home/aspectgroup/.gem/ruby/1.8/gems/rake-0.8.3/lib/rake.rb:578:in `invoke_with_call_chain'
/usr/lib/ruby/1.8/monitor.rb:242:in `synchronize'
/home/aspectgroup/.gem/ruby/1.8/gems/rake-0.8.3/lib/rake.rb:571:in `invoke_with_call_chain'
/home/aspectgroup/.gem/ruby/1.8/gems/rake-0.8.3/lib/rake.rb:588:in `invoke_prerequisites'
/home/aspectgroup/.gem/ruby/1.8/gems/rake-0.8.3/lib/rake.rb:585:in `each'
/home/aspectgroup/.gem/ruby/1.8/gems/rake-0.8.3/lib/rake.rb:585:in `invoke_prerequisites'
/home/aspectgroup/.gem/ruby/1.8/gems/rake-0.8.3/lib/rake.rb:577:in `invoke_with_call_chain'
/usr/lib/ruby/1.8/monitor.rb:242:in `synchronize'
/home/aspectgroup/.gem/ruby/1.8/gems/rake-0.8.3/lib/rake.rb:571:in `invoke_with_call_chain'
/home/aspectgroup/.gem/ruby/1.8/gems/rake-0.8.3/lib/rake.rb:564:in `invoke'
/home/aspectgroup/.gem/ruby/1.8/gems/rake-0.8.3/lib/rake.rb:2019:in `invoke_task'
/home/aspectgroup/.gem/ruby/1.8/gems/rake-0.8.3/lib/rake.rb:1997:in `top_level'
/home/aspectgroup/.gem/ruby/1.8/gems/rake-0.8.3/lib/rake.rb:1997:in `each'
/home/aspectgroup/.gem/ruby/1.8/gems/rake-0.8.3/lib/rake.rb:1997:in `top_level'
/home/aspectgroup/.gem/ruby/1.8/gems/rake-0.8.3/lib/rake.rb:2036:in `standard_exception_handling'
/home/aspectgroup/.gem/ruby/1.8/gems/rake-0.8.3/lib/rake.rb:1991:in `top_level'
/home/aspectgroup/.gem/ruby/1.8/gems/rake-0.8.3/lib/rake.rb:1970:in `run'
/home/aspectgroup/.gem/ruby/1.8/gems/rake-0.8.3/lib/rake.rb:2036:in `standard_exception_handling'
/home/aspectgroup/.gem/ruby/1.8/gems/rake-0.8.3/lib/rake.rb:1967:in `run'
/home/aspectgroup/.gem/ruby/1.8/gems/rake-0.8.3/bin/rake:31
/usr/bin/rake:19:in `load'
/usr/bin/rake:19

does anyone know what could be causing this problem?

TIA yorkie wink

Re: rake db:migrate works, rake RAILS_ENV=production db:migrate does not..

Looks like your missing a gem what's on line 13 of environment.rb?

Re: rake db:migrate works, rake RAILS_ENV=production db:migrate does not..

I am having the same problem mentioned by maumac but i do not seem to understand his solution.

i have moved my development from windows to linux. i am trying to migrate all of my data.

when i use the rake db:schema:load i get the error of table does not exist...

it is the same exact trace as posted above

Re: rake db:migrate works, rake RAILS_ENV=production db:migrate does not..

i had the same problem, but i fixed it.

the issue was that i had a custom initialization file (in /config/initializers/my_custom_config.rb), and since my custom init code used database tables that do not exist, it broke.

just removing the custom init made rake db:schema:load RAILS_ENV=test --trace run fine.

Re: rake db:migrate works, rake RAILS_ENV=production db:migrate does not..

I've been having the exact same problems

** Invoke db:schema:load (first_time)
** Invoke environment (first_time)
** Execute environment
rake aborted!
Mysql::Error: Table 'wiggle_production.users' doesn't exist: SELECT * FROM `users`
/usr/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active_record/connection_adapters/abstract_adapter.rb:188:in `log'
/usr/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active_record/connection_adapters/mysql_adapter.rb:309:in `execute'
/usr/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active_record/connection_adapters/mysql_adapter.rb:563:in `select'
/usr/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active_record/connection_adapters/abstract/database_statements.rb:7:in `select_all_without_query_cache'
/usr/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active_record/connection_adapters/abstract/query_cache.rb:62:in `select_all'
/usr/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active_record/base.rb:635:in `find_by_sql'
/usr/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active_record/base.rb:1490:in `find_every'
/usr/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active_record/base.rb:589:in `find'
/home/demo/public_html/wiggle/releases/20090511200038/app/controllers/users_controller.rb:2
/usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
/usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'
/usr/lib/ruby/gems/1.8/gems/activesupport-2.2.2/lib/active_support/dependencies.rb:155:in `require'
/usr/lib/ruby/gems/1.8/gems/activesupport-2.2.2/lib/active_support/dependencies.rb:262:in `require_or_load'
/usr/lib/ruby/gems/1.8/gems/activesupport-2.2.2/lib/active_support/dependencies.rb:221:in `depend_on'
/usr/lib/ruby/gems/1.8/gems/activesupport-2.2.2/lib/active_support/dependencies.rb:133:in `require_dependency'
/usr/lib/ruby/gems/1.8/gems/rails-2.2.2/lib/initializer.rb:368:in `load_application_classes'
/usr/lib/ruby/gems/1.8/gems/rails-2.2.2/lib/initializer.rb:367:in `each'
/usr/lib/ruby/gems/1.8/gems/rails-2.2.2/lib/initializer.rb:367:in `load_application_classes'
/usr/lib/ruby/gems/1.8/gems/rails-2.2.2/lib/initializer.rb:365:in `each'
/usr/lib/ruby/gems/1.8/gems/rails-2.2.2/lib/initializer.rb:365:in `load_application_classes'
/usr/lib/ruby/gems/1.8/gems/rails-2.2.2/lib/initializer.rb:185:in `process'
/usr/lib/ruby/gems/1.8/gems/rails-2.2.2/lib/initializer.rb:112:in `send'
/usr/lib/ruby/gems/1.8/gems/rails-2.2.2/lib/initializer.rb:112:in `run'
/home/demo/public_html/wiggle/releases/20090511200038/config/environment.rb:13
/usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
/usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'
/usr/lib/ruby/gems/1.8/gems/activesupport-2.2.2/lib/active_support/dependencies.rb:153:in `require'
/usr/lib/ruby/gems/1.8/gems/activesupport-2.2.2/lib/active_support/dependencies.rb:521:in `new_constants_in'
/usr/lib/ruby/gems/1.8/gems/activesupport-2.2.2/lib/active_support/dependencies.rb:153:in `require'
/usr/lib/ruby/gems/1.8/gems/rails-2.2.2/lib/tasks/misc.rake:3
/usr/lib/ruby/gems/1.8/gems/rake-0.8.4/lib/rake.rb:617:in `call'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.4/lib/rake.rb:617:in `execute'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.4/lib/rake.rb:612:in `each'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.4/lib/rake.rb:612:in `execute'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.4/lib/rake.rb:578:in `invoke_with_call_chain'
/usr/lib/ruby/1.8/monitor.rb:242:in `synchronize'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.4/lib/rake.rb:571:in `invoke_with_call_chain'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.4/lib/rake.rb:588:in `invoke_prerequisites'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.4/lib/rake.rb:585:in `each'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.4/lib/rake.rb:585:in `invoke_prerequisites'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.4/lib/rake.rb:577:in `invoke_with_call_chain'
/usr/lib/ruby/1.8/monitor.rb:242:in `synchronize'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.4/lib/rake.rb:571:in `invoke_with_call_chain'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.4/lib/rake.rb:564:in `invoke'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.4/lib/rake.rb:2027:in `invoke_task'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.4/lib/rake.rb:2005:in `top_level'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.4/lib/rake.rb:2005:in `each'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.4/lib/rake.rb:2005:in `top_level'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.4/lib/rake.rb:2044:in `standard_exception_handling'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.4/lib/rake.rb:1999:in `top_level'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.4/lib/rake.rb:1977:in `run'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.4/lib/rake.rb:2044:in `standard_exception_handling'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.4/lib/rake.rb:1974:in `run'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.4/bin/rake:31
/usr/bin/rake:19:in `load'
/usr/bin/rake:19

Re: rake db:migrate works, rake RAILS_ENV=production db:migrate does not..

Setting config.cache_classes = false in production.rb worked for me.

Re: rake db:migrate works, rake RAILS_ENV=production db:migrate does not..

Clearly!

Re: rake db:migrate works, rake RAILS_ENV=production db:migrate does not..

kukuruza wrote:

Clearly!

Right.

bmharper wrote:

Setting config.cache_classes = false in production.rb worked for me

This is a smell. Fix the actual problem, don't do this. Now your rails app will load everything every request instead of caching everything. This is only good development mode. In production mode this is awful.

Re: rake db:migrate works, rake RAILS_ENV=production db:migrate does not..

I had the same problem and upgrading the thinking_sphinx plugin fixed things.  I agree with cherring, find the real problem and fix it.  It's only going to bite you later if you don't.

Re: rake db:migrate works, rake RAILS_ENV=production db:migrate does not..

I had the same problem.
I was creating constants in my models that where getting values from the database.

VISIBLE_STATUSES = self.find(:all,  :conditions => "visible is true").map do |l|

It of course didn't work on the initial launch of the production environment since the table hadn't been created yet.

All I did was

  begin
    VISIBLE_STATUSES = self.find(:all,  :conditions => "visible is true").map do |l|
      l.id
    end
  rescue
    # making sure it doesn't prevent the initial rake db:migrate from working
  end

Re: rake db:migrate works, rake RAILS_ENV=production db:migrate does not..

Just in case anyone comes looking for this issue wioth rails 3.2, you should set config.cache_classes = false in your production.rb file, this fixes the symptom but you are going to have to look harder for the cause as you are most likely loading the whole rails stack in some initialisation process, check your initialiser files and your RakeFile, make sure it doesn't have a load_tasks line

What you want and what you need are too often not the same thing!
When your head is hurting from trying to solve a problem, stop standing on it. When you are the right way up you will see the problem differently and you just might find the solution.
(Quote by me 15th July 2009)