Tiago
Tiago

Reputation: 2966

Rails: rake db:migrate -> stack level too deep

I've never seen this error before, and I've no idea what I should be looking for.

$ rake db:migrate --trace
(in /Users/tscolari/Projetos/movies)
** Invoke db:migrate (first_time)
** Invoke environment (first_time)
** Execute environment
** Execute db:migrate
rake aborted!
stack level too deep
/opt/local/lib/ruby/gems/1.8/gems/scrubyt-0.4.06/lib/scrubyt/utils/ruby_extensions.rb:66:in `write'
/opt/local/lib/ruby/gems/1.8/gems/scrubyt-0.4.06/lib/scrubyt/utils/ruby_extensions.rb:66:in `collect'
/opt/local/lib/ruby/gems/1.8/gems/scrubyt-0.4.06/lib/scrubyt/utils/ruby_extensions.rb:66:in `write'
/opt/local/lib/ruby/gems/1.8/gems/scrubyt-0.4.06/lib/scrubyt/utils/ruby_extensions.rb:66:in `write'
/opt/local/lib/ruby/gems/1.8/gems/activesupport-3.0.0/lib/active_support/buffered_logger.rb:108:in `flush'
/opt/local/lib/ruby/gems/1.8/gems/activesupport-3.0.0/lib/active_support/buffered_logger.rb:101:in `synchronize'
/opt/local/lib/ruby/gems/1.8/gems/activesupport-3.0.0/lib/active_support/buffered_logger.rb:101:in `flush'
/opt/local/lib/ruby/gems/1.8/gems/activesupport-3.0.0/lib/active_support/buffered_logger.rb:125:in `auto_flush'
/opt/local/lib/ruby/gems/1.8/gems/activesupport-3.0.0/lib/active_support/buffered_logger.rb:66:in `add'
/opt/local/lib/ruby/gems/1.8/gems/activesupport-3.0.0/lib/active_support/buffered_logger.rb:77:in `debug'
/opt/local/lib/ruby/gems/1.8/gems/activerecord-3.0.0/lib/active_record/connection_adapters/abstract_adapter.rb:201:in `log'
/opt/local/lib/ruby/gems/1.8/gems/activerecord-3.0.0/lib/active_record/connection_adapters/sqlite_adapter.rb:135:in `execute'
/opt/local/lib/ruby/gems/1.8/gems/activerecord-3.0.0/lib/active_record/connection_adapters/sqlite_adapter.rb:180:in `tables'
/opt/local/lib/ruby/gems/1.8/gems/activerecord-3.0.0/lib/active_record/connection_adapters/abstract/schema_statements.rb:21:in `table_exists?'
/opt/local/lib/ruby/gems/1.8/gems/activerecord-3.0.0/lib/active_record/connection_adapters/abstract/schema_statements.rb:429:in `initialize_schema_migrations_table'
/opt/local/lib/ruby/gems/1.8/gems/activerecord-3.0.0/lib/active_record/migration.rb:487:in `initialize'
/opt/local/lib/ruby/gems/1.8/gems/activerecord-3.0.0/lib/active_record/migration.rb:433:in `new'
/opt/local/lib/ruby/gems/1.8/gems/activerecord-3.0.0/lib/active_record/migration.rb:433:in `up'
/opt/local/lib/ruby/gems/1.8/gems/activerecord-3.0.0/lib/active_record/migration.rb:415:in `migrate'
/opt/local/lib/ruby/gems/1.8/gems/activerecord-3.0.0/lib/active_record/railties/databases.rake:142
/opt/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:636:in `call'
/opt/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:636:in `execute'
/opt/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:631:in `each'
/opt/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:631:in `execute'
/opt/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:597:in `invoke_with_call_chain'
/opt/local/lib/ruby/1.8/monitor.rb:242:in `synchronize'
/opt/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:590:in `invoke_with_call_chain'
/opt/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:583:in `invoke'
/opt/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2051:in `invoke_task'
/opt/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2029:in `top_level'
/opt/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2029:in `each'
/opt/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2029:in `top_level'
/opt/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2068:in `standard_exception_handling'
/opt/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2023:in `top_level'
/opt/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2001:in `run'
/opt/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2068:in `standard_exception_handling'
/opt/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:1998:in `run'
/opt/local/lib/ruby/gems/1.8/gems/rake-0.8.7/bin/rake:31
/opt/local/bin/rake:19:in `load'
/opt/local/bin/rake:19

First I thought it could be something wrong in one of my migrations, so I removed them all to check, and the error still. And strangely the application/console starts without any problem:

$ rails server
=> Booting Mongrel
=> Rails 3.0.0 application starting in development on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server

And then I have no idea where to look for the error. Any help?

Upvotes: 4

Views: 3811

Answers (3)

Promise Preston
Promise Preston

Reputation: 28978

I had a similar challenge when working on a Rails 4 application on Ubuntu 20.04.

When I run the command rake:db migrate, I get the error below:

rake aborted! SystemStackError: stack level too deep /home/mycomputer/Projects/my-project/config/environment.rb:5:in <top (required)>' /home/mycomputer/.rbenv/versions/2.5.8/bin/bundle:23:in load' /home/mycomputer/.rbenv/versions/2.5.8/bin/bundle:23:in `' Tasks: TOP => db:migrate => environment (See full trace by running task with --trace)

Here's how I fixed it:

After debugging, I figured the issue was caused by some outdated gems, which were causing some dependency issues.

All I did was update the gems to the version compatible with the project using the command:

bundle update

You could also comment out the gems and try installing them one after the other after you uncomment each of them. If you are lucky enough to trace the gem causing the issue, then you could just update that gem only using

bundle update gem_name

Another way, although not advisable (since you might run into some dependency compatibility issues) will be to delete your Gemfile.lock file and then re-install your gems afresh using:

bundle install 

Or:

bundle update

Upvotes: 0

Tiago
Tiago

Reputation: 2966

Okay, I tried everything, rake db:reset, deleting all migrations, and so on...

The problem was a gem. scrubyt gem in my gemfile caused all this trouble...

Upvotes: 2

Sam 山
Sam 山

Reputation: 42863

Sometimes db's get out of wack. What you can do is save your current schema and then reset your db rake db:reset and make a new migration script/generate migration add_old_db migrating your entire old schema as the new migration. Just copy and paste your old schema into the new migration and it will make new tables as it might have been before. Of course your data will be destroyed in the process.

Upvotes: -1

Related Questions