rails 升级 nil:NilClass 的未定义方法“each”和未定义方法“include?”后的活动记录错误nil:NilClass

Active-record error after rails upgrade undefined method `each' for nil:NilClass and undefined method `include?' for nil:NilClass

我一步步升级rails4.2.10到6.0。但是当我尝试将 rails 5.2.4.4 升级到 6.0 时,我无法像 Object.all 那样查询,它给了我 undefined method 'each' for nil:NilClass 错误。当我尝试调用 Object 时,它为 nil:NilClass 提供了 未定义的方法 'include?'。即使我无法 运行 它在 运行ning rails active_storage:update 之后创建的活动存储的迁移文件,我也不明白哪里出了问题,我也没有看到任何人有同样的经历。

Started GET "/" for 127.0.0.1 at 2020-12-15 16:48:40 +0300
   (2.4ms)  SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
Started GET "/tr" for 127.0.0.1 at 2020-12-15 16:48:41 +0300
Processing by WelcomeController#homepage as HTML
  Parameters: {"locale"=>"tr"}
Completed 500 Internal Server Error in 51ms (ActiveRecord: 4.0ms | Allocations: 13240)



NoMethodError - undefined method `each' for nil:NilClass:
  app/controllers/application_controller.rb:92:in `set_locale'
89-      @footer_categories = Category.where(id: ft_cate_ids).order('order_number DESC')
90-      @posts_footer = PostBlog.where(status: 1).order('id DESC').limit(3)
91-    elsif Rails.env.development?
92-      @posts_footer = PostBlog.where(status: 1).order('id DESC').limit(3)
93-    end

这个是请求错误,没有迁移的代码


➜  upgrade git:(upgrade) ✗ rails db:migrate --trace
** Invoke db:migrate (first_time)
** Invoke db:load_config (first_time)
** Invoke environment (first_time)
** Execute environment
** Execute db:load_config
** Execute db:migrate
== 20201215113528 AddServiceNameToActiveStorageBlobs: migrating ===============
-- column_exists?(:active_storage_blobs, :service_name)
rails aborted!
StandardError: An error has occurred, this and all later migrations canceled:

undefined method `each' for nil:NilClass
/home/mesabuca/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/descriptive_statistics-2.5.1/lib/descriptive_statistics/support/convert.rb:37:in `to_array'
/home/mesabuca/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/descriptive_statistics-2.5.1/lib/descriptive_statistics/support/convert.rb:8:in `convert'
/home/mesabuca/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/descriptive_statistics-2.5.1/lib/descriptive_statistics/sum.rb:3:in `sum'
/home/mesabuca/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/activesupport-6.1.0/lib/active_support/core_ext/enumerable.rb:246:in `sum'
/home/mesabuca/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/activerecord-6.1.0/lib/active_record/connection_adapters/postgresql/schema_statements.rb:691:in `sequence_name_from_parts'
/home/mesabuca/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/activerecord-6.1.0/lib/active_record/connection_adapters/postgresql/schema_statements.rb:663:in `new_column_from_field'
/home/mesabuca/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/activerecord-6.1.0/lib/active_record/connection_adapters/abstract/schema_statements.rb:117:in `block in columns'
/home/mesabuca/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/activerecord-6.1.0/lib/active_record/connection_adapters/abstract/schema_statements.rb:116:in `map'
/home/mesabuca/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/activerecord-6.1.0/lib/active_record/connection_adapters/abstract/schema_statements.rb:116:in `columns'
/home/mesabuca/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/activerecord-6.1.0/lib/active_record/connection_adapters/abstract/schema_statements.rb:144:in `column_exists?'
/home/mesabuca/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/activerecord-6.1.0/lib/active_record/migration.rb:929:in `block in method_missing'
/home/mesabuca/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/activerecord-6.1.0/lib/active_record/migration.rb:897:in `block in say_with_time'
/home/mesabuca/.rbenv/versions/2.7.1/lib/ruby/2.7.0/benchmark.rb:293:in `measure'
/home/mesabuca/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/activerecord-6.1.0/lib/active_record/migration.rb:897:in `say_with_time'
/home/mesabuca/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/activerecord-6.1.0/lib/active_record/migration.rb:918:in `method_missing'
/home/mesabuca/Workspace/upgrade/db/migrate/20201215113528_add_service_name_to_active_storage_blobs.active_storage.rb:4:in `up'
/home/mesabuca/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/activerecord-6.1.0/lib/active_record/migration.rb:870:in `public_send'
/home/mesabuca/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/activerecord-6.1.0/lib/active_record/migration.rb:870:in `exec_migration'
/home/mesabuca/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/activerecord-6.1.0/lib/active_record/migration.rb:851:in `block (2 levels) in migrate'
/home/mesabuca/.rbenv/versions/2.7.1/lib/ruby/2.7.0/benchmark.rb:293:in `measure'
/home/mesabuca/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/activerecord-6.1.0/lib/active_record/migration.rb:850:in `block in migrate'
/home/mesabuca/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/activerecord-6.1.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:462:in `with_connection'
/home/mesabuca/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/activerecord-6.1.0/lib/active_record/migration.rb:849:in `migrate'
/home/mesabuca/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/activerecord-6.1.0/lib/active_record/migration.rb:1037:in `migrate'
/home/mesabuca/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/activerecord-6.1.0/lib/active_record/migration.rb:1329:in `block in execute_migration_in_transaction'
/home/mesabuca/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/activerecord-6.1.0/lib/active_record/migration.rb:1380:in `block in ddl_transaction'
/home/mesabuca/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/activerecord-6.1.0/lib/active_record/connection_adapters/abstract/database_statements.rb:320:in `block in transaction'
/home/mesabuca/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/activerecord-6.1.0/lib/active_record/connection_adapters/abstract/transaction.rb:310:in `block in within_new_transaction'
/home/mesabuca/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/activesupport-6.1.0/lib/active_support/concurrency/load_interlock_aware_monitor.rb:26:in `block (2 levels) in synchronize'
/home/mesabuca/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/activesupport-6.1.0/lib/active_support/concurrency/load_interlock_aware_monitor.rb:25:in `handle_interrupt'
/home/mesabuca/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/activesupport-6.1.0/lib/active_support/concurrency/load_interlock_aware_monitor.rb:25:in `block in synchronize'
/home/mesabuca/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/activesupport-6.1.0/lib/active_support/concurrency/load_interlock_aware_monitor.rb:21:in `handle_interrupt'
/home/mesabuca/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/activesupport-6.1.0/lib/active_support/concurrency/load_interlock_aware_monitor.rb:21:in `synchronize'
/home/mesabuca/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/activerecord-6.1.0/lib/active_record/connection_adapters/abstract/transaction.rb:308:in `within_new_transaction'
/home/mesabuca/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/activerecord-6.1.0/lib/active_record/connection_adapters/abstract/database_statements.rb:320:in `transaction'
/home/mesabuca/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/activerecord-6.1.0/lib/active_record/transactions.rb:209:in `transaction'
/home/mesabuca/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/activerecord-6.1.0/lib/active_record/migration.rb:1380:in `ddl_transaction'
/home/mesabuca/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/activerecord-6.1.0/lib/active_record/migration.rb:1328:in `execute_migration_in_transaction'
/home/mesabuca/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/activerecord-6.1.0/lib/active_record/migration.rb:1302:in `each'
/home/mesabuca/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/activerecord-6.1.0/lib/active_record/migration.rb:1302:in `migrate_without_lock'
/home/mesabuca/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/activerecord-6.1.0/lib/active_record/migration.rb:1251:in `block in migrate'
/home/mesabuca/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/activerecord-6.1.0/lib/active_record/migration.rb:1401:in `block in with_advisory_lock'
/home/mesabuca/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/activerecord-6.1.0/lib/active_record/migration.rb:1416:in `block in with_advisory_lock_connection'
/home/mesabuca/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/activerecord-6.1.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:462:in `with_connection'
/home/mesabuca/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/activerecord-6.1.0/lib/active_record/migration.rb:1416:in `with_advisory_lock_connection'
/home/mesabuca/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/activerecord-6.1.0/lib/active_record/migration.rb:1397:in `with_advisory_lock'
/home/mesabuca/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/activerecord-6.1.0/lib/active_record/migration.rb:1251:in `migrate'
/home/mesabuca/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/activerecord-6.1.0/lib/active_record/migration.rb:1086:in `up'
/home/mesabuca/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/activerecord-6.1.0/lib/active_record/migration.rb:1061:in `migrate'
/home/mesabuca/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/activerecord-6.1.0/lib/active_record/tasks/database_tasks.rb:237:in `migrate'
/home/mesabuca/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/activerecord-6.1.0/lib/active_record/railties/databases.rake:92:in `block (3 levels) in <top (required)>'
/home/mesabuca/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/activerecord-6.1.0/lib/active_record/railties/databases.rake:90:in `each'
/home/mesabuca/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/activerecord-6.1.0/lib/active_record/railties/databases.rake:90:in `block (2 levels) in <top (required)>'
/home/mesabuca/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/rake-13.0.1/lib/rake/task.rb:281:in `block in execute'
/home/mesabuca/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/rake-13.0.1/lib/rake/task.rb:281:in `each'
/home/mesabuca/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/rake-13.0.1/lib/rake/task.rb:281:in `execute'
/home/mesabuca/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/rake-13.0.1/lib/rake/task.rb:219:in `block in invoke_with_call_chain'
/home/mesabuca/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/rake-13.0.1/lib/rake/task.rb:199:in `synchronize'
/home/mesabuca/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/rake-13.0.1/lib/rake/task.rb:199:in `invoke_with_call_chain'
/home/mesabuca/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/rake-13.0.1/lib/rake/task.rb:188:in `invoke'
/home/mesabuca/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/rake-13.0.1/lib/rake/application.rb:160:in `invoke_task'
/home/mesabuca/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/rake-13.0.1/lib/rake/application.rb:116:in `block (2 levels) in top_level'
/home/mesabuca/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/rake-13.0.1/lib/rake/application.rb:116:in `each'
/home/mesabuca/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/rake-13.0.1/lib/rake/application.rb:116:in `block in top_level'
/home/mesabuca/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/rake-13.0.1/lib/rake/application.rb:125:in `run_with_threads'
/home/mesabuca/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/rake-13.0.1/lib/rake/application.rb:110:in `top_level'
/home/mesabuca/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/railties-6.1.0/lib/rails/commands/rake/rake_command.rb:24:in `block (2 levels) in perform'
/home/mesabuca/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/rake-13.0.1/lib/rake/application.rb:186:in `standard_exception_handling'
/home/mesabuca/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/railties-6.1.0/lib/rails/commands/rake/rake_command.rb:24:in `block in perform'
/home/mesabuca/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/rake-13.0.1/lib/rake/rake_module.rb:59:in `with_application'
/home/mesabuca/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/railties-6.1.0/lib/rails/commands/rake/rake_command.rb:18:in `perform'
/home/mesabuca/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/railties-6.1.0/lib/rails/command.rb:52:in `invoke'
/home/mesabuca/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/railties-6.1.0/lib/rails/commands.rb:18:in `<top (required)>'
bin/rails:4:in `require'
bin/rails:4:in `<main>'

Caused by:
NoMethodError: undefined method `each' for nil:NilClass
/home/mesabuca/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/descriptive_statistics-2.5.1/lib/descriptive_statistics/support/convert.rb:37:in `to_array'
/home/mesabuca/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/descriptive_statistics-2.5.1/lib/descriptive_statistics/support/convert.rb:8:in `convert'
/home/mesabuca/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/descriptive_statistics-2.5.1/lib/descriptive_statistics/sum.rb:3:in `sum'
/home/mesabuca/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/activesupport-6.1.0/lib/active_support/core_ext/enumerable.rb:246:in `sum'
/home/mesabuca/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/activerecord-6.1.0/lib/active_record/connection_adapters/postgresql/schema_statements.rb:691:in `sequence_name_from_parts'
/home/mesabuca/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/activerecord-6.1.0/lib/active_record/connection_adapters/postgresql/schema_statements.rb:663:in `new_column_from_field'
/home/mesabuca/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/activerecord-6.1.0/lib/active_record/connection_adapters/abstract/schema_statements.rb:117:in `block in columns'
/home/mesabuca/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/activerecord-6.1.0/lib/active_record/connection_adapters/abstract/schema_statements.rb:116:in `map'
/home/mesabuca/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/activerecord-6.1.0/lib/active_record/connection_adapters/abstract/schema_statements.rb:116:in `columns'
/home/mesabuca/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/activerecord-6.1.0/lib/active_record/connection_adapters/abstract/schema_statements.rb:144:in `column_exists?'
/home/mesabuca/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/activerecord-6.1.0/lib/active_record/migration.rb:929:in `block in method_missing'
/home/mesabuca/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/activerecord-6.1.0/lib/active_record/migration.rb:897:in `block in say_with_time'
/home/mesabuca/.rbenv/versions/2.7.1/lib/ruby/2.7.0/benchmark.rb:293:in `measure'
/home/mesabuca/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/activerecord-6.1.0/lib/active_record/migration.rb:897:in `say_with_time'
/home/mesabuca/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/activerecord-6.1.0/lib/active_record/migration.rb:918:in `method_missing'
/home/mesabuca/Workspace/upgrade/db/migrate/20201215113528_add_service_name_to_active_storage_blobs.active_storage.rb:4:in `up'
/home/mesabuca/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/activerecord-6.1.0/lib/active_record/migration.rb:870:in `public_send'
/home/mesabuca/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/activerecord-6.1.0/lib/active_record/migration.rb:870:in `exec_migration'
/home/mesabuca/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/activerecord-6.1.0/lib/active_record/migration.rb:851:in `block (2 levels) in migrate'
/home/mesabuca/.rbenv/versions/2.7.1/lib/ruby/2.7.0/benchmark.rb:293:in `measure'
/home/mesabuca/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/activerecord-6.1.0/lib/active_record/migration.rb:850:in `block in migrate'
/home/mesabuca/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/activerecord-6.1.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:462:in `with_connection'
/home/mesabuca/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/activerecord-6.1.0/lib/active_record/migration.rb:849:in `migrate'
/home/mesabuca/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/activerecord-6.1.0/lib/active_record/migration.rb:1037:in `migrate'
/home/mesabuca/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/activerecord-6.1.0/lib/active_record/migration.rb:1329:in `block in execute_migration_in_transaction'
/home/mesabuca/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/activerecord-6.1.0/lib/active_record/migration.rb:1380:in `block in ddl_transaction'
/home/mesabuca/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/activerecord-6.1.0/lib/active_record/connection_adapters/abstract/database_statements.rb:320:in `block in transaction'
/home/mesabuca/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/activerecord-6.1.0/lib/active_record/connection_adapters/abstract/transaction.rb:310:in `block in within_new_transaction'
/home/mesabuca/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/activesupport-6.1.0/lib/active_support/concurrency/load_interlock_aware_monitor.rb:26:in `block (2 levels) in synchronize'
/home/mesabuca/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/activesupport-6.1.0/lib/active_support/concurrency/load_interlock_aware_monitor.rb:25:in `handle_interrupt'
/home/mesabuca/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/activesupport-6.1.0/lib/active_support/concurrency/load_interlock_aware_monitor.rb:25:in `block in synchronize'
/home/mesabuca/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/activesupport-6.1.0/lib/active_support/concurrency/load_interlock_aware_monitor.rb:21:in `handle_interrupt'
/home/mesabuca/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/activesupport-6.1.0/lib/active_support/concurrency/load_interlock_aware_monitor.rb:21:in `synchronize'
/home/mesabuca/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/activerecord-6.1.0/lib/active_record/connection_adapters/abstract/transaction.rb:308:in `within_new_transaction'
/home/mesabuca/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/activerecord-6.1.0/lib/active_record/connection_adapters/abstract/database_statements.rb:320:in `transaction'
/home/mesabuca/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/activerecord-6.1.0/lib/active_record/transactions.rb:209:in `transaction'
/home/mesabuca/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/activerecord-6.1.0/lib/active_record/migration.rb:1380:in `ddl_transaction'
/home/mesabuca/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/activerecord-6.1.0/lib/active_record/migration.rb:1328:in `execute_migration_in_transaction'
/home/mesabuca/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/activerecord-6.1.0/lib/active_record/migration.rb:1302:in `each'
/home/mesabuca/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/activerecord-6.1.0/lib/active_record/migration.rb:1302:in `migrate_without_lock'
/home/mesabuca/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/activerecord-6.1.0/lib/active_record/migration.rb:1251:in `block in migrate'
/home/mesabuca/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/activerecord-6.1.0/lib/active_record/migration.rb:1401:in `block in with_advisory_lock'
/home/mesabuca/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/activerecord-6.1.0/lib/active_record/migration.rb:1416:in `block in with_advisory_lock_connection'
/home/mesabuca/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/activerecord-6.1.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:462:in `with_connection'
/home/mesabuca/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/activerecord-6.1.0/lib/active_record/migration.rb:1416:in `with_advisory_lock_connection'
/home/mesabuca/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/activerecord-6.1.0/lib/active_record/migration.rb:1397:in `with_advisory_lock'
/home/mesabuca/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/activerecord-6.1.0/lib/active_record/migration.rb:1251:in `migrate'
/home/mesabuca/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/activerecord-6.1.0/lib/active_record/migration.rb:1086:in `up'
/home/mesabuca/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/activerecord-6.1.0/lib/active_record/migration.rb:1061:in `migrate'
/home/mesabuca/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/activerecord-6.1.0/lib/active_record/tasks/database_tasks.rb:237:in `migrate'
/home/mesabuca/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/activerecord-6.1.0/lib/active_record/railties/databases.rake:92:in `block (3 levels) in <top (required)>'
/home/mesabuca/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/activerecord-6.1.0/lib/active_record/railties/databases.rake:90:in `each'
/home/mesabuca/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/activerecord-6.1.0/lib/active_record/railties/databases.rake:90:in `block (2 levels) in <top (required)>'
/home/mesabuca/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/rake-13.0.1/lib/rake/task.rb:281:in `block in execute'
/home/mesabuca/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/rake-13.0.1/lib/rake/task.rb:281:in `each'
/home/mesabuca/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/rake-13.0.1/lib/rake/task.rb:281:in `execute'
/home/mesabuca/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/rake-13.0.1/lib/rake/task.rb:219:in `block in invoke_with_call_chain'
/home/mesabuca/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/rake-13.0.1/lib/rake/task.rb:199:in `synchronize'
/home/mesabuca/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/rake-13.0.1/lib/rake/task.rb:199:in `invoke_with_call_chain'
/home/mesabuca/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/rake-13.0.1/lib/rake/task.rb:188:in `invoke'
/home/mesabuca/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/rake-13.0.1/lib/rake/application.rb:160:in `invoke_task'
/home/mesabuca/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/rake-13.0.1/lib/rake/application.rb:116:in `block (2 levels) in top_level'
/home/mesabuca/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/rake-13.0.1/lib/rake/application.rb:116:in `each'
/home/mesabuca/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/rake-13.0.1/lib/rake/application.rb:116:in `block in top_level'
/home/mesabuca/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/rake-13.0.1/lib/rake/application.rb:125:in `run_with_threads'
/home/mesabuca/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/rake-13.0.1/lib/rake/application.rb:110:in `top_level'
/home/mesabuca/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/railties-6.1.0/lib/rails/commands/rake/rake_command.rb:24:in `block (2 levels) in perform'
/home/mesabuca/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/rake-13.0.1/lib/rake/application.rb:186:in `standard_exception_handling'
/home/mesabuca/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/railties-6.1.0/lib/rails/commands/rake/rake_command.rb:24:in `block in perform'
/home/mesabuca/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/rake-13.0.1/lib/rake/rake_module.rb:59:in `with_application'
/home/mesabuca/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/railties-6.1.0/lib/rails/commands/rake/rake_command.rb:18:in `perform'
/home/mesabuca/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/railties-6.1.0/lib/rails/command.rb:52:in `invoke'
/home/mesabuca/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/railties-6.1.0/lib/rails/commands.rb:18:in `<top (required)>'
bin/rails:4:in `require'
bin/rails:4:in `<main>'
Tasks: TOP => db:migrate

这是使用回溯的迁移错误。

您的错误信息表明问题出在descriptive_statistics(第三方)gem。我在项目的 github 页面中找到了 this issue -- 这似乎正是您的问题。

看来这个问题与 rails 升级无关,而是将 ruby 升级到 2.4+

作为suggested on the github issue,您可以通过以下方式解决它:

# Add require: false in your Gemfile:
gem 'descriptive_statistics', require: false

# explicitly require the library, and extend arrays where needed in your code:
require 'descriptive_statistics/safe'

data = []
data.extend(DescriptiveStatistics)
data.sum