### Is there an existing issue for this?

- [X] I have searched the existing issues

### Current behaviour

crash

### Expected behaviour

no crash

### Steps to reproduce

* Compile 79e8247ddb166f9b980f40249b7372a502402a4d
* Type `migratewallet`

### Relevant log output

```
wallet/scriptpubkeyman.cpp:1915: std::optional<MigrationData> wallet::LegacyScriptPubKeyMan::MigrateToDescriptor(): Assertion `IsMine(desc_spk) != ISMINE_NO' failed.
Aborted (core dumped)
```


### How did you obtain Bitcoin Core

Compiled from source

### What version of Bitcoin Core are you using?

current master

### Operating system and version

Linux

### Machine specifications

_No response_
}
void CWalUpgradeDescriptorCache()
{
    if (!IsWalFlagSet(WALLET_FLAG_DESCRIPTORS) || IsLocked() || IsWalFlagSet(WALLET_FLAG_LAST_HARDENED_XPUB_CACHED)) {
        return;
    }
    for (ScriptPubKeyMan* spkm  GetAllScriptPubKeyMans()) {
        DescriptorScriptPubKeyMan* desc_spkm = dynamic_cast<DescriptorScriptPubKeyMan*>(spkm);
        desc_spkm->UpgradeDescriptorCache();
    }
    SetWalFlag(WALLET_FLAG_LAST_HARDENED_XPUB_CACHED);
}
bool CWalUnlock(const SecureString& strWalPassphrase, bool accept_no_keys)
{
    CCrypter crypter;
    CKeyingMaterial _vMasterKey;
    {
        LOCK(cs_wal);
        for (const MasterKeyMapvalue_type& pMasterKey  mapMasterKeys)
        {
            if(!crypter.SetKeyFromPassphrase(strWalPassphrase, pMasterKey.second.vchSalt, pMasterKey.second.nDeriveIterations, pMasterKey.second.nDerivationMethod))
                return false;
            if (!crypter.Decrypt(pMasterKey.second.vchCryptedKey, _vMasterKey))
                continue; // t
            if (Unlock(_vMasterKey, accept_no_keys)) {
                // N
                UpgradeKeyMetadata();
                // N
                UpgradeDescriptorCache();
                return true;