このエラーの原因が見つかりません: OpenSSL::Cipher::CipherError

概要

Rails 6 内で何かをしようとするとエラーが発生します (データベースの移行、サーバーの起動、データベースの削除など)。

私が受け取るエラーは次のとおりです:

ActiveSupport::MessageEncryptor::InvalidMessage: ActiveSupport::MessageEncryptor::InvalidMessage
C:/Users/environment/shafrica/config/environment.rb:5:in `<top (required)>'

Caused by:
OpenSSL::Cipher::CipherError:
C:/Users/environment/shafrica/config/environment.rb:5:in `<top (required)>'
Tasks: TOP => db:migrate => db:load_config => environment
(See full trace by running task with --trace)

Stackoverflow を調べてみました (例: this と this) しかし、彼らは私の問題を解決しませんでした。 Postgresql データベースに関連しているような気がしますが、決定的なものには到達できませんでした。誰かアイデアはありますか?

スタックトレース:

49: from bin/rails:4:in `<main>'
48: from bin/rails:4:in `require'
47: from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/railties-6.0.2.1/lib/rails/commands.rb:18:in <top (required)>'
46: from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/railties-6.0.2.1/lib/rails/command.rb:46:in `invoke'
45: from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/railties-6.0.2.1/lib/rails/command/base.rb:69:in `perform'
44: from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/thor-0.20.3/lib/thor.rb:387:in `dispatch'
43: from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/thor-0.20.3/lib/thor/invocation.rb:126:in `invoke_command'
42: from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/thor-0.20.3/lib/thor/command.rb:27:in `run'
41: from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/railties-6.0.2.1/lib/rails/commands/server/server_command.rb:138:in `perform'
40: from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/railties-6.0.2.1/lib/rails/commands/server/server_command.rb:138:in `tap'
39: from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/railties-6.0.2.1/lib/rails/commands/server/server_command.rb:147:in `block in perform'
38: from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/railties-6.0.2.1/lib/rails/commands/server/server_command.rb:37:in `start'
37: from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/railties-6.0.2.1/lib/rails/commands/server/server_command.rb:77:in `log_to_stdout'
36: from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/rack-2.2.2/lib/rack/server.rb:422:in `wrapped_app'
35: from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/rack-2.2.2/lib/rack/server.rb:249:in `app'
34: from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/rack-2.2.2/lib/rack/server.rb:349:in `build_app_and_options_from_config'
33: from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/rack-2.2.2/lib/rack/builder.rb:66:in `parse_file'
32: from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/rack-2.2.2/lib/rack/builder.rb:105:in `load_file'
31: from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/rack-2.2.2/lib/rack/builder.rb:116:in `new_from_string'
30: from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/rack-2.2.2/lib/rack/builder.rb:116:in `eval'
29: from config.ru:3:in `block in <main>'
28: from config.ru:3:in `require_relative'
27: from C:/Users/environment/shafrica/config/environment.rb:5:in `<top (required)>'
26: from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/railties-6.0.2.1/lib/rails/application.rb:363:in `initialize!'
25: from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/railties-6.0.2.1/lib/rails/initializable.rb:60:in `run_initializers'
24: from C:/Ruby26-x64/lib/ruby/2.6.0/tsort.rb:205:in `tsort_each'
23: from C:/Ruby26-x64/lib/ruby/2.6.0/tsort.rb:226:in `tsort_each'
22: from C:/Ruby26-x64/lib/ruby/2.6.0/tsort.rb:347:in `each_strongly_connected_component'
21: from C:/Ruby26-x64/lib/ruby/2.6.0/tsort.rb:347:in `call'
20: from C:/Ruby26-x64/lib/ruby/2.6.0/tsort.rb:347:in `each'
19: from C:/Ruby26-x64/lib/ruby/2.6.0/tsort.rb:349:in `block in each_strongly_connected_component'
18: from C:/Ruby26-x64/lib/ruby/2.6.0/tsort.rb:431:in `each_strongly_connected_component_from'
17: from C:/Ruby26-x64/lib/ruby/2.6.0/tsort.rb:350:in `block (2 levels) in each_strongly_connected_component'
16: from C:/Ruby26-x64/lib/ruby/2.6.0/tsort.rb:228:in `block in tsort_each'
15: from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/railties-6.0.2.1/lib/rails/initializable.rb:61:in `block in run_initializers'
14: from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/railties-6.0.2.1/lib/rails/initializable.rb:32:in `run'
13: from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/railties-6.0.2.1/lib/rails/initializable.rb:32:in `instance_exec'
12: from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/devise-4.7.1/lib/devise/rails.rb:37:in `block in <class:Engine>'        
11: from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/devise-4.7.1/lib/devise/secret_key_finder.rb:10:in `find'
10: from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/devise-4.7.1/lib/devise/secret_key_finder.rb:24:in `key_exists?'         
9: from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/activesupport-6.0.2.1/lib/active_support/core_ext/module/delegation.rb:297:in `method_missing'
8: from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/activesupport-6.0.2.1/lib/active_support/encrypted_configuration.rb:38:in `options'
7: from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/activesupport-6.0.2.1/lib/active_support/encrypted_configuration.rb:33:in `config'
6: from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/activesupport-6.0.2.1/lib/active_support/encrypted_configuration.rb:21:in `read'
5: from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/activesupport-6.0.2.1/lib/active_support/encrypted_file.rb:43:in `read'
4: from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/activesupport-6.0.2.1/lib/active_support/encrypted_file.rb:80:in `decrypt'
3: from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/activesupport-6.0.2.1/lib/active_support/messages/rotator.rb:21:in `decrypt_and_verify'
2: from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/activesupport-6.0.2.1/lib/active_support/message_encryptor.rb:157:in `decrypt_and_verify'
1: from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/activesupport-6.0.2.1/lib/active_support/message_encryptor.rb:201:in `_decrypt' C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/activesupport-6.0.2.1/lib/active_support/message_encryptor.rb:201:in `final': OpenSSL::Cipher::CipherError

解決策

これは通常、資格情報が正しく設定されていない場合に発生します。このような場合には

bin/rails credentials:edit (If you have EDITOR set in your $PATH)
or
EDITOR="nano" bin/rails credentials:edit (If you don't have EDITOR set in your $PATH)

これにより、新しい credentials.yml.enc が生成されます。

これでエラーが修正されるはずです。