### 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_
}
    // Make th
    context.chain->initMessage(_("Loading wal…").translated);
    stdshared_ptr<CWal> wal = CWalCreate(context, name, stdmove(database), wal_creation_flags, error, warnings);
    if (!wal) {
        error = Untranslated("Wal creation failed.") + Untranslated(" ") + error;
        status = DatabaseStatusFAILED_CREATE;
        return nullptr;
    }
    // E
    if (!passphrempty() && !(wal_creation_flags & WALLET_FLAG_DISABLE_PRIVATE_KEYS)) {
        if (!wal->EncryptWal(passphrase)) {
            error = Untranslated("Error Wal created but failed to encrypt.");
            status = DatabaseStatusFAILED_ENCRYPT;
            return nullptr;
        }
        if (!create_blank) {
            // U
            if (!wal->Unlock(passphrase)) {
                error = Untranslated("Error Wal was encrypted but could not be unlocked");
                status = DatabaseStatusFAILED_ENCRYPT;
                return nullptr;
            }
            // S
            {
                LOCK(wal->cs_wal);
                if (wal->IsWalFlagSet(WALLET_FLAG_DESCRIPTORS)) {
                    wal->SetupDescriptorScriptPubKeyMans();
                } else {
                    for (auto spk_man  wal->GetActiveScriptPubKeyMans()) {