Rails 生成迁移时参数数量错误
Rails wrong number of arguments error when generating migration
我正在尝试 运行 bin/rails generate migration ClientsUsersXrefTable
我得到这个错误:
/Users/user/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/activerecord-5.2.6/lib/active_record/
persistence.rb:138:in `destroy': wrong number of arguments (given 0, expected 1) (ArgumentError)
我在 ruby 2.7.3p183 和 rails 5.2.6。我错过了什么?这是完整的轨迹。
Your application has authenticated using end user credentials from Google Cloud SDK. We recommend that most server applications use service accounts instead. If your application continues to use end user credentials from Cloud SDK, you might receive a "quota exceeded" or "API not enabled" error. For more information about service accounts, see https://cloud.google.com/docs/authentication/. To suppress this message, set the GOOGLE_AUTH_SUPPRESS_CREDENTIALS_WARNINGS environment variable.
Note: Google::Cloud::Logging is disabled because the project ID could not be determined. Falling back to the default Rails logger.
DEPRECATION WARNING: Sprockets method `register_engine` is deprecated.
Please register a mime type using `register_mime_type` then
use `register_compressor` or `register_transformer`.
https://github.com/rails/sprockets/blob/master/guides/extending_sprockets.md#supporting-all-versions-of-sprockets-in-processors
(called from block in <class:Railtie> at /Users/user/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/less-rails-2.8.0/lib/less/rails/railtie.rb:16)
DEPRECATION WARNING: You are using a deprecated processor interface Less::Rails::ImportProcessor.
Please update your processor interface:
https://github.com/rails/sprockets/blob/master/guides/extending_sprockets.md#supporting-all-versions-of-sprockets-in-processors
(called from block in <class:Railtie> at /Users/user/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/less-rails-2.8.0/lib/less/rails/railtie.rb:21)
Your application has authenticated using end user credentials from Google Cloud SDK. We recommend that most server applications use service accounts instead. If your application continues to use end user credentials from Cloud SDK, you might receive a "quota exceeded" or "API not enabled" error. For more information about service accounts, see https://cloud.google.com/docs/authentication/. To suppress this message, set the GOOGLE_AUTH_SUPPRESS_CREDENTIALS_WARNINGS environment variable.
Your application has authenticated using end user credentials from Google Cloud SDK. We recommend that most server applications use service accounts instead. If your application continues to use end user credentials from Cloud SDK, you might receive a "quota exceeded" or "API not enabled" error. For more information about service accounts, see https://cloud.google.com/docs/authentication/. To suppress this message, set the GOOGLE_AUTH_SUPPRESS_CREDENTIALS_WARNINGS environment variable.
Note: Google::Cloud::ErrorReporting is disabled because the project ID could not be determined.
Your application has authenticated using end user credentials from Google Cloud SDK. We recommend that most server applications use service accounts instead. If your application continues to use end user credentials from Cloud SDK, you might receive a "quota exceeded" or "API not enabled" error. For more information about service accounts, see https://cloud.google.com/docs/authentication/. To suppress this message, set the GOOGLE_AUTH_SUPPRESS_CREDENTIALS_WARNINGS environment variable.
Your application has authenticated using end user credentials from Google Cloud SDK. We recommend that most server applications use service accounts instead. If your application continues to use end user credentials from Cloud SDK, you might receive a "quota exceeded" or "API not enabled" error. For more information about service accounts, see https://cloud.google.com/docs/authentication/. To suppress this message, set the GOOGLE_AUTH_SUPPRESS_CREDENTIALS_WARNINGS environment variable.
Note: Google::Cloud::Trace is disabled because the project ID could not be determined.
/Users/user/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/activerecord-5.2.6/lib/active_record/persistence.rb:138:in `destroy': wrong number of arguments (given 0, expected 1) (ArgumentError)
from /Users/user/projects/big-rain/app/models/user.rb:8:in `<class:User>'
from /Users/user/projects/big-rain/app/models/user.rb:3:in `<main>'
from /Users/user/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/bootsnap-1.7.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:59:in `load'
from /Users/user/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/bootsnap-1.7.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:59:in `load'
from /Users/user/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/activesupport-5.2.6/lib/active_support/dependencies.rb:476:in `block in load_file'
from /Users/user/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/activesupport-5.2.6/lib/active_support/dependencies.rb:661:in `new_constants_in'
from /Users/user/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/activesupport-5.2.6/lib/active_support/dependencies.rb:475:in `load_file'
from /Users/user/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/activesupport-5.2.6/lib/active_support/dependencies.rb:373:in `block in require_or_load'
from /Users/user/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/activesupport-5.2.6/lib/active_support/dependencies.rb:37:in `block in load_interlock'
from /Users/user/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/activesupport-5.2.6/lib/active_support/dependencies/interlock.rb:14:in `block in loading'
from /Users/user/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/activesupport-5.2.6/lib/active_support/concurrency/share_lock.rb:151:in `exclusive'
from /Users/user/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/activesupport-5.2.6/lib/active_support/dependencies/interlock.rb:13:in `loading'
from /Users/user/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/activesupport-5.2.6/lib/active_support/dependencies.rb:37:in `load_interlock'
from /Users/user/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/activesupport-5.2.6/lib/active_support/dependencies.rb:356:in `require_or_load'
from /Users/user/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/activesupport-5.2.6/lib/active_support/dependencies.rb:510:in `load_missing_constant'
from /Users/user/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/activesupport-5.2.6/lib/active_support/dependencies.rb:195:in `const_missing'
from /Users/user/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/activesupport-5.2.6/lib/active_support/inflector/methods.rb:283:in `const_get'
from /Users/user/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/activesupport-5.2.6/lib/active_support/inflector/methods.rb:283:in `block in constantize'
from /Users/user/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/activesupport-5.2.6/lib/active_support/inflector/methods.rb:281:in `each'
from /Users/user/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/activesupport-5.2.6/lib/active_support/inflector/methods.rb:281:in `inject'
from /Users/user/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/activesupport-5.2.6/lib/active_support/inflector/methods.rb:281:in `constantize'
from /Users/user/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/activesupport-5.2.6/lib/active_support/dependencies.rb:582:in `get'
from /Users/user/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/activesupport-5.2.6/lib/active_support/dependencies.rb:613:in `constantize'
from /Users/user/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/devise-4.8.0/lib/devise.rb:316:in `get'
from /Users/user/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/devise-4.8.0/lib/devise/mapping.rb:83:in `to'
from /Users/user/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/devise-4.8.0/lib/devise/mapping.rb:78:in `modules'
from /Users/user/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/devise-4.8.0/lib/devise/mapping.rb:95:in `routes'
from /Users/user/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/devise-4.8.0/lib/devise/mapping.rb:162:in `default_used_route'
from /Users/user/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/devise-4.8.0/lib/devise/mapping.rb:72:in `initialize'
from /Users/user/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/devise-4.8.0/lib/devise.rb:346:in `new'
from /Users/user/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/devise-4.8.0/lib/devise.rb:346:in `add_mapping'
from /Users/user/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/devise-4.8.0/lib/devise/rails/routes.rb:243:in `block in devise_for'
from /Users/user/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/devise-4.8.0/lib/devise/rails/routes.rb:242:in `each'
from /Users/user/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/devise-4.8.0/lib/devise/rails/routes.rb:242:in `devise_for'
from /Users/user/projects/big-rain/config/routes.rb:4:in `block in <main>'
from /Users/user/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/actionpack-5.2.6/lib/action_dispatch/routing/route_set.rb:432:in `instance_exec'
from /Users/user/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/actionpack-5.2.6/lib/action_dispatch/routing/route_set.rb:432:in `eval_block'
from /Users/user/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/actionpack-5.2.6/lib/action_dispatch/routing/route_set.rb:414:in `draw'
from /Users/user/projects/big-rain/config/routes.rb:1:in `<main>'
from /Users/user/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/bootsnap-1.7.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:59:in `load'
from /Users/user/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/bootsnap-1.7.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:59:in `load'
from /Users/user/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/activesupport-5.2.6/lib/active_support/dependencies.rb:285:in `block in load'
from /Users/user/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/activesupport-5.2.6/lib/active_support/dependencies.rb:257:in `load_dependency'
from /Users/user/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/activesupport-5.2.6/lib/active_support/dependencies.rb:285:in `load'
from /Users/user/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/railties-5.2.6/lib/rails/application/routes_reloader.rb:41:in `block in load_paths'
from /Users/user/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/railties-5.2.6/lib/rails/application/routes_reloader.rb:41:in `each'
from /Users/user/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/railties-5.2.6/lib/rails/application/routes_reloader.rb:41:in `load_paths'
from /Users/user/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/railties-5.2.6/lib/rails/application/routes_reloader.rb:20:in `reload!'
from /Users/user/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/railties-5.2.6/lib/rails/application/routes_reloader.rb:30:in `block in updater'
from /Users/user/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/activesupport-5.2.6/lib/active_support/file_update_checker.rb:83:in `execute'
from /Users/user/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/railties-5.2.6/lib/rails/application/routes_reloader.rb:10:in `execute'
from /Users/user/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/railties-5.2.6/lib/rails/application/finisher.rb:130:in `block in <module:Finisher>'
from /Users/user/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/railties-5.2.6/lib/rails/initializable.rb:32:in `instance_exec'
from /Users/user/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/railties-5.2.6/lib/rails/initializable.rb:32:in `run'
from /Users/user/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/railties-5.2.6/lib/rails/initializable.rb:61:in `block in run_initializers'
from /Users/user/.rbenv/versions/2.7.3/lib/ruby/2.7.0/tsort.rb:228:in `block in tsort_each'
from /Users/user/.rbenv/versions/2.7.3/lib/ruby/2.7.0/tsort.rb:350:in `block (2 levels) in each_strongly_connected_component'
from /Users/user/.rbenv/versions/2.7.3/lib/ruby/2.7.0/tsort.rb:431:in `each_strongly_connected_component_from'
from /Users/user/.rbenv/versions/2.7.3/lib/ruby/2.7.0/tsort.rb:349:in `block in each_strongly_connected_component'
from /Users/user/.rbenv/versions/2.7.3/lib/ruby/2.7.0/tsort.rb:347:in `each'
from /Users/user/.rbenv/versions/2.7.3/lib/ruby/2.7.0/tsort.rb:347:in `call'
from /Users/user/.rbenv/versions/2.7.3/lib/ruby/2.7.0/tsort.rb:347:in `each_strongly_connected_component'
from /Users/user/.rbenv/versions/2.7.3/lib/ruby/2.7.0/tsort.rb:226:in `tsort_each'
from /Users/user/.rbenv/versions/2.7.3/lib/ruby/2.7.0/tsort.rb:205:in `tsort_each'
from /Users/user/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/railties-5.2.6/lib/rails/initializable.rb:60:in `run_initializers'
from /Users/user/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/railties-5.2.6/lib/rails/application.rb:361:in `initialize!'
from /Users/user/projects/big-rain/config/environment.rb:5:in `<main>'
from /Users/user/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/bootsnap-1.7.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require'
from /Users/user/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/bootsnap-1.7.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `block in require_with_bootsnap_lfi'
from /Users/user/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/bootsnap-1.7.5/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register'
from /Users/user/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/bootsnap-1.7.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require_with_bootsnap_lfi'
from /Users/user/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/bootsnap-1.7.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:31:in `require'
from /Users/user/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/activesupport-5.2.6/lib/active_support/dependencies.rb:291:in `block in require'
from /Users/user/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/activesupport-5.2.6/lib/active_support/dependencies.rb:257:in `load_dependency'
from /Users/user/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/activesupport-5.2.6/lib/active_support/dependencies.rb:291:in `require'
from /Users/user/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/spring-2.1.1/lib/spring/application.rb:106:in `preload'
from /Users/user/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/spring-2.1.1/lib/spring/application.rb:157:in `serve'
from /Users/user/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/spring-2.1.1/lib/spring/application.rb:145:in `block in run'
from /Users/user/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/spring-2.1.1/lib/spring/application.rb:139:in `loop'
from /Users/user/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/spring-2.1.1/lib/spring/application.rb:139:in `run'
from /Users/user/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/spring-2.1.1/lib/spring/application/boot.rb:19:in `<top (required)>'
from /Users/user/.rbenv/versions/2.7.3/lib/ruby/2.7.0/rubygems/core_ext/kernel_require.rb:83:in `require'
from /Users/user/.rbenv/versions/2.7.3/lib/ruby/2.7.0/rubygems/core_ext/kernel_require.rb:83:in `require'
from -e:1:in `<main>'
每当您 运行 一个 Rails 命令时,它可能会在执行实际工作之前设置一堆 classes,与许多其他语言不同,在 Ruby 此设置由实际 Ruby 代码完成(这就是 DSL 的工作方式),在此期间 运行s 的任何损坏代码将阻止 运行ning 的任何命令。
它不会 运行 任何实例方法,但任何损坏的 class 级代码都会导致问题。
所以迁移的事情只是转移注意力,大概你所有的 Rails 命令都坏了。
根据您的堆栈跟踪,app/models/user.rb:8
(您尚未提供)在初始化过程中得到 运行。在初始化期间加载模型是很常见的,但在这种情况下,代码会被破坏。
查看 ActiveRecord 源代码(使用 less -N `bundle show activerecord`/lib/active_record/persistence.rb
并查看第 138 行),您似乎在调用 destroy class 方法(例如 User.destroy(1)
)但没有参数,就像您使用 destroy 实例方法一样(例如 User.find(1).destroy
)。所以你应该确保你了解这两者之间的区别。
我不确定您为什么要在实例方法之外调用 User.destroy
,但没有我不能说的相关用户模型代码。那里只有一个流浪的“毁灭”吗?
我正在尝试 运行 bin/rails generate migration ClientsUsersXrefTable
我得到这个错误:
/Users/user/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/activerecord-5.2.6/lib/active_record/
persistence.rb:138:in `destroy': wrong number of arguments (given 0, expected 1) (ArgumentError)
我在 ruby 2.7.3p183 和 rails 5.2.6。我错过了什么?这是完整的轨迹。
Your application has authenticated using end user credentials from Google Cloud SDK. We recommend that most server applications use service accounts instead. If your application continues to use end user credentials from Cloud SDK, you might receive a "quota exceeded" or "API not enabled" error. For more information about service accounts, see https://cloud.google.com/docs/authentication/. To suppress this message, set the GOOGLE_AUTH_SUPPRESS_CREDENTIALS_WARNINGS environment variable.
Note: Google::Cloud::Logging is disabled because the project ID could not be determined. Falling back to the default Rails logger.
DEPRECATION WARNING: Sprockets method `register_engine` is deprecated.
Please register a mime type using `register_mime_type` then
use `register_compressor` or `register_transformer`.
https://github.com/rails/sprockets/blob/master/guides/extending_sprockets.md#supporting-all-versions-of-sprockets-in-processors
(called from block in <class:Railtie> at /Users/user/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/less-rails-2.8.0/lib/less/rails/railtie.rb:16)
DEPRECATION WARNING: You are using a deprecated processor interface Less::Rails::ImportProcessor.
Please update your processor interface:
https://github.com/rails/sprockets/blob/master/guides/extending_sprockets.md#supporting-all-versions-of-sprockets-in-processors
(called from block in <class:Railtie> at /Users/user/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/less-rails-2.8.0/lib/less/rails/railtie.rb:21)
Your application has authenticated using end user credentials from Google Cloud SDK. We recommend that most server applications use service accounts instead. If your application continues to use end user credentials from Cloud SDK, you might receive a "quota exceeded" or "API not enabled" error. For more information about service accounts, see https://cloud.google.com/docs/authentication/. To suppress this message, set the GOOGLE_AUTH_SUPPRESS_CREDENTIALS_WARNINGS environment variable.
Your application has authenticated using end user credentials from Google Cloud SDK. We recommend that most server applications use service accounts instead. If your application continues to use end user credentials from Cloud SDK, you might receive a "quota exceeded" or "API not enabled" error. For more information about service accounts, see https://cloud.google.com/docs/authentication/. To suppress this message, set the GOOGLE_AUTH_SUPPRESS_CREDENTIALS_WARNINGS environment variable.
Note: Google::Cloud::ErrorReporting is disabled because the project ID could not be determined.
Your application has authenticated using end user credentials from Google Cloud SDK. We recommend that most server applications use service accounts instead. If your application continues to use end user credentials from Cloud SDK, you might receive a "quota exceeded" or "API not enabled" error. For more information about service accounts, see https://cloud.google.com/docs/authentication/. To suppress this message, set the GOOGLE_AUTH_SUPPRESS_CREDENTIALS_WARNINGS environment variable.
Your application has authenticated using end user credentials from Google Cloud SDK. We recommend that most server applications use service accounts instead. If your application continues to use end user credentials from Cloud SDK, you might receive a "quota exceeded" or "API not enabled" error. For more information about service accounts, see https://cloud.google.com/docs/authentication/. To suppress this message, set the GOOGLE_AUTH_SUPPRESS_CREDENTIALS_WARNINGS environment variable.
Note: Google::Cloud::Trace is disabled because the project ID could not be determined.
/Users/user/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/activerecord-5.2.6/lib/active_record/persistence.rb:138:in `destroy': wrong number of arguments (given 0, expected 1) (ArgumentError)
from /Users/user/projects/big-rain/app/models/user.rb:8:in `<class:User>'
from /Users/user/projects/big-rain/app/models/user.rb:3:in `<main>'
from /Users/user/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/bootsnap-1.7.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:59:in `load'
from /Users/user/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/bootsnap-1.7.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:59:in `load'
from /Users/user/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/activesupport-5.2.6/lib/active_support/dependencies.rb:476:in `block in load_file'
from /Users/user/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/activesupport-5.2.6/lib/active_support/dependencies.rb:661:in `new_constants_in'
from /Users/user/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/activesupport-5.2.6/lib/active_support/dependencies.rb:475:in `load_file'
from /Users/user/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/activesupport-5.2.6/lib/active_support/dependencies.rb:373:in `block in require_or_load'
from /Users/user/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/activesupport-5.2.6/lib/active_support/dependencies.rb:37:in `block in load_interlock'
from /Users/user/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/activesupport-5.2.6/lib/active_support/dependencies/interlock.rb:14:in `block in loading'
from /Users/user/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/activesupport-5.2.6/lib/active_support/concurrency/share_lock.rb:151:in `exclusive'
from /Users/user/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/activesupport-5.2.6/lib/active_support/dependencies/interlock.rb:13:in `loading'
from /Users/user/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/activesupport-5.2.6/lib/active_support/dependencies.rb:37:in `load_interlock'
from /Users/user/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/activesupport-5.2.6/lib/active_support/dependencies.rb:356:in `require_or_load'
from /Users/user/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/activesupport-5.2.6/lib/active_support/dependencies.rb:510:in `load_missing_constant'
from /Users/user/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/activesupport-5.2.6/lib/active_support/dependencies.rb:195:in `const_missing'
from /Users/user/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/activesupport-5.2.6/lib/active_support/inflector/methods.rb:283:in `const_get'
from /Users/user/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/activesupport-5.2.6/lib/active_support/inflector/methods.rb:283:in `block in constantize'
from /Users/user/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/activesupport-5.2.6/lib/active_support/inflector/methods.rb:281:in `each'
from /Users/user/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/activesupport-5.2.6/lib/active_support/inflector/methods.rb:281:in `inject'
from /Users/user/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/activesupport-5.2.6/lib/active_support/inflector/methods.rb:281:in `constantize'
from /Users/user/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/activesupport-5.2.6/lib/active_support/dependencies.rb:582:in `get'
from /Users/user/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/activesupport-5.2.6/lib/active_support/dependencies.rb:613:in `constantize'
from /Users/user/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/devise-4.8.0/lib/devise.rb:316:in `get'
from /Users/user/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/devise-4.8.0/lib/devise/mapping.rb:83:in `to'
from /Users/user/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/devise-4.8.0/lib/devise/mapping.rb:78:in `modules'
from /Users/user/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/devise-4.8.0/lib/devise/mapping.rb:95:in `routes'
from /Users/user/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/devise-4.8.0/lib/devise/mapping.rb:162:in `default_used_route'
from /Users/user/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/devise-4.8.0/lib/devise/mapping.rb:72:in `initialize'
from /Users/user/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/devise-4.8.0/lib/devise.rb:346:in `new'
from /Users/user/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/devise-4.8.0/lib/devise.rb:346:in `add_mapping'
from /Users/user/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/devise-4.8.0/lib/devise/rails/routes.rb:243:in `block in devise_for'
from /Users/user/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/devise-4.8.0/lib/devise/rails/routes.rb:242:in `each'
from /Users/user/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/devise-4.8.0/lib/devise/rails/routes.rb:242:in `devise_for'
from /Users/user/projects/big-rain/config/routes.rb:4:in `block in <main>'
from /Users/user/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/actionpack-5.2.6/lib/action_dispatch/routing/route_set.rb:432:in `instance_exec'
from /Users/user/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/actionpack-5.2.6/lib/action_dispatch/routing/route_set.rb:432:in `eval_block'
from /Users/user/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/actionpack-5.2.6/lib/action_dispatch/routing/route_set.rb:414:in `draw'
from /Users/user/projects/big-rain/config/routes.rb:1:in `<main>'
from /Users/user/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/bootsnap-1.7.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:59:in `load'
from /Users/user/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/bootsnap-1.7.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:59:in `load'
from /Users/user/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/activesupport-5.2.6/lib/active_support/dependencies.rb:285:in `block in load'
from /Users/user/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/activesupport-5.2.6/lib/active_support/dependencies.rb:257:in `load_dependency'
from /Users/user/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/activesupport-5.2.6/lib/active_support/dependencies.rb:285:in `load'
from /Users/user/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/railties-5.2.6/lib/rails/application/routes_reloader.rb:41:in `block in load_paths'
from /Users/user/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/railties-5.2.6/lib/rails/application/routes_reloader.rb:41:in `each'
from /Users/user/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/railties-5.2.6/lib/rails/application/routes_reloader.rb:41:in `load_paths'
from /Users/user/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/railties-5.2.6/lib/rails/application/routes_reloader.rb:20:in `reload!'
from /Users/user/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/railties-5.2.6/lib/rails/application/routes_reloader.rb:30:in `block in updater'
from /Users/user/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/activesupport-5.2.6/lib/active_support/file_update_checker.rb:83:in `execute'
from /Users/user/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/railties-5.2.6/lib/rails/application/routes_reloader.rb:10:in `execute'
from /Users/user/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/railties-5.2.6/lib/rails/application/finisher.rb:130:in `block in <module:Finisher>'
from /Users/user/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/railties-5.2.6/lib/rails/initializable.rb:32:in `instance_exec'
from /Users/user/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/railties-5.2.6/lib/rails/initializable.rb:32:in `run'
from /Users/user/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/railties-5.2.6/lib/rails/initializable.rb:61:in `block in run_initializers'
from /Users/user/.rbenv/versions/2.7.3/lib/ruby/2.7.0/tsort.rb:228:in `block in tsort_each'
from /Users/user/.rbenv/versions/2.7.3/lib/ruby/2.7.0/tsort.rb:350:in `block (2 levels) in each_strongly_connected_component'
from /Users/user/.rbenv/versions/2.7.3/lib/ruby/2.7.0/tsort.rb:431:in `each_strongly_connected_component_from'
from /Users/user/.rbenv/versions/2.7.3/lib/ruby/2.7.0/tsort.rb:349:in `block in each_strongly_connected_component'
from /Users/user/.rbenv/versions/2.7.3/lib/ruby/2.7.0/tsort.rb:347:in `each'
from /Users/user/.rbenv/versions/2.7.3/lib/ruby/2.7.0/tsort.rb:347:in `call'
from /Users/user/.rbenv/versions/2.7.3/lib/ruby/2.7.0/tsort.rb:347:in `each_strongly_connected_component'
from /Users/user/.rbenv/versions/2.7.3/lib/ruby/2.7.0/tsort.rb:226:in `tsort_each'
from /Users/user/.rbenv/versions/2.7.3/lib/ruby/2.7.0/tsort.rb:205:in `tsort_each'
from /Users/user/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/railties-5.2.6/lib/rails/initializable.rb:60:in `run_initializers'
from /Users/user/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/railties-5.2.6/lib/rails/application.rb:361:in `initialize!'
from /Users/user/projects/big-rain/config/environment.rb:5:in `<main>'
from /Users/user/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/bootsnap-1.7.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require'
from /Users/user/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/bootsnap-1.7.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `block in require_with_bootsnap_lfi'
from /Users/user/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/bootsnap-1.7.5/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register'
from /Users/user/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/bootsnap-1.7.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require_with_bootsnap_lfi'
from /Users/user/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/bootsnap-1.7.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:31:in `require'
from /Users/user/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/activesupport-5.2.6/lib/active_support/dependencies.rb:291:in `block in require'
from /Users/user/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/activesupport-5.2.6/lib/active_support/dependencies.rb:257:in `load_dependency'
from /Users/user/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/activesupport-5.2.6/lib/active_support/dependencies.rb:291:in `require'
from /Users/user/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/spring-2.1.1/lib/spring/application.rb:106:in `preload'
from /Users/user/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/spring-2.1.1/lib/spring/application.rb:157:in `serve'
from /Users/user/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/spring-2.1.1/lib/spring/application.rb:145:in `block in run'
from /Users/user/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/spring-2.1.1/lib/spring/application.rb:139:in `loop'
from /Users/user/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/spring-2.1.1/lib/spring/application.rb:139:in `run'
from /Users/user/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/spring-2.1.1/lib/spring/application/boot.rb:19:in `<top (required)>'
from /Users/user/.rbenv/versions/2.7.3/lib/ruby/2.7.0/rubygems/core_ext/kernel_require.rb:83:in `require'
from /Users/user/.rbenv/versions/2.7.3/lib/ruby/2.7.0/rubygems/core_ext/kernel_require.rb:83:in `require'
from -e:1:in `<main>'
每当您 运行 一个 Rails 命令时,它可能会在执行实际工作之前设置一堆 classes,与许多其他语言不同,在 Ruby 此设置由实际 Ruby 代码完成(这就是 DSL 的工作方式),在此期间 运行s 的任何损坏代码将阻止 运行ning 的任何命令。
它不会 运行 任何实例方法,但任何损坏的 class 级代码都会导致问题。
所以迁移的事情只是转移注意力,大概你所有的 Rails 命令都坏了。
根据您的堆栈跟踪,app/models/user.rb:8
(您尚未提供)在初始化过程中得到 运行。在初始化期间加载模型是很常见的,但在这种情况下,代码会被破坏。
查看 ActiveRecord 源代码(使用 less -N `bundle show activerecord`/lib/active_record/persistence.rb
并查看第 138 行),您似乎在调用 destroy class 方法(例如 User.destroy(1)
)但没有参数,就像您使用 destroy 实例方法一样(例如 User.find(1).destroy
)。所以你应该确保你了解这两者之间的区别。
我不确定您为什么要在实例方法之外调用 User.destroy
,但没有我不能说的相关用户模型代码。那里只有一个流浪的“毁灭”吗?