### 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_
AddScriptPubKeyMan(id, stdmove(spk_manager));
                AddActiveScriptPubKeyMan(id, t, internal);
            }
        }
    }
}
void CWalAddActiveScriptPubKeyMan(uint256 id, OutputType type, bool internal)
{
    WalBatch batch(GetDatabase());
    if (!batch.WriteActiveScriptPubKeyMan(static_cast<uint8_t>(type), id, internal)) {
        throw stdruntime_error(stdstring(__func__) + " writing active ScriptPubKeyMan id failed");
    }
    LoadActiveScriptPubKeyMan(id, type, internal);
}
void CWalLoadActiveScriptPubKeyMan(uint256 id, OutputType type, bool internal)
{
    // Activating ScriptPubKeyManager for a given output and change type is incompatible with legacy wals.
    // Legacy wals have only one ScriptPubKeyManager and it's active for all output and change types.
    Assert(IsWalFlagSet(WALLET_FLAG_DESCRIPTORS));
    WalLogPrintf("Setting spkMan to active id = %s, type = %s, internal = %s\n", id.ToString(), FormatOutputType(type), internal ? "true"  "false");
    auto& spk_mans = internal ? m_internal_spk_managers  m_external_spk_managers;
    auto& spk_mans_other = internal ? m_external_spk_managers  m_internal_spk_managers;
    auto spk_man = m_spk_managers.at(id).get();
    spk_mans[type] = spk_man;
    const auto it = spk_mans_other.find(type);
    if (it != spk_mans_other.end() && it->second == spk_man) {
        spk_mans_other.erase(type);
    }
    NotifyCanGetAddressesChanged();
}