How to encrypt credentials with a new master key?

I’ve got a Rails 6 project. The first time I did rails credentials:edit a master key had been generated. Since I didn’t know about the master key before, I am not sure whether I already had a master key file. The default is that Rails is supposed to create that for me when I create a new project, AFAIK and I double checked that by creating another demo project. So I suppose I had one.

If I already had a master key once the project was created with rails new I do not know why rails again created a master key and replaced the old one.

Now I can not do rails credentials:edit because then I get “Couldn’t decrypt config/credentials.yml.enc. Perhaps you passed the wrong key?”

How would I use this new master key to encrypt my secrets?

Well, just remove the old encrypted file and Rails will create a new one with the new master key. I think my title was a bit wrong. Once you loose the master key, all the credentials are lost. So a better title would be “How to create a new encrypted credentials file with a new master key”.

¯_(ツ)_/¯