【问题标题】:Rails: rake db:migrate -> stack level too deepRails: rake db:migrate -> 堆栈级别太深
【发布时间】:2023-03-03 12:55:01
【问题描述】:

我以前从未见过这个错误,我不知道我应该寻找什么。

$ 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

首先我认为我的一个迁移可能有问题,所以我将它们全部删除以检查,错误仍然存​​在。 奇怪的是,应用程序/控制台启动时没有任何问题:

$ 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

然后我不知道在哪里寻找错误。有什么帮助吗?

【问题讨论】:

  • 这个错误是在开发环境之外出现的吗?另外,我注意到scrubyt 中的跟踪失败——你能禁用这个 gem 并重试迁移吗?

标签: ruby-on-rails ruby-on-rails-3 migration rake


【解决方案1】:

好的, 我尝试了一切,rake db:reset,删除所有迁移,等等......

问题是宝石。我的 gemfile 中的scrubyt gem 造成了所有这些麻烦......

【讨论】:

【解决方案2】:

Ubuntu 20.04

上开发 Rails 4 应用程序时,我遇到了类似的挑战

当我运行命令rake:db migrate 时,我收到以下错误:

rake 中止! SystemStackError:堆栈级别太深 /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 `' 任务:TOP => db:migrate => 环境 (通过使用 --trace 运行任务查看完整跟踪)

这是我修复它的方法

调试了几个小时后,我发现问题是由一些过时的 gem 引起的,这导致了一些依赖问题。

我所做的只是使用以下命令将 gem 更新到与项目兼容的版本:

bundle update

您也可以注释掉这些 gem,然后在取消注释后一个接一个地安装它们。如果您有幸追踪到导致问题的 gem,那么您可以只使用更新该 gem

bundle update gem_name

另一种方法,虽然不是可取的(因为您可能会遇到一些依赖项兼容性问题),但将删除您的 Gemfile.lock 文件,然后使用以下方法重新安装您的 gem:

bundle install 

bundle update

就是这样。

我希望这会有所帮助

【讨论】:

    【解决方案3】:

    有时 db 会失控。您可以做的是保存当前架构,然后重置您的数据库 rake db:reset 并进行新的迁移 script/generate migration add_old_db 将整个旧架构迁移为新迁移。只需将旧模式复制并粘贴到新迁移中,它就会像以前一样创建新表。当然,您的数据会在此过程中被销毁。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-07-24
      • 1970-01-01
      • 2011-11-11
      • 1970-01-01
      • 2017-08-19
      • 2018-09-12
      相关资源
      最近更新 更多