### 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_
walInstance->InitWalFlags(wal_creation_flags);
        // Only create LegacyScriptPubKeyMan when not  wal
        if (!walInstance->IsWalFlagSet(WALLET_FLAG_DESCRIPTORS)) {
            walInstance->SetupLegacyScriptPubKeyMan();
        }
        if ((wal_creation_flags & WALLET_FLAG_EXTERNAL_SIGNER) || !(wal_creation_flags & (WALLET_FLAG_DISABLE_PRIVATE_KEYS | WALLET_FLAG_BLANK_WALLET))) {
            LOCK(walInstance->cs_wal);
            if (walInstance->IsWalFlagSet(WALLET_FLAG_DESCRIPTORS)) {
                walInstance->SetupDescriptorScriptPubKeyMans();
                // SetupDe
            } else {
                // Legacy 
                for (auto spk_man  walInstance->GetActiveScriptPubKeyMans()) {
                    if (!spk_man->SetupGeneration()) {
                        error = _("Unable to generate initial keys");
                        return nullptr;
                    }
                }
            }
        }
        if (chain) {
            walInstance->chainStateFlushed(chain->getTipLocator());
        }
    } else if (wal_creation_flags & WALLET_FLAG_DISABLE_PRIVATE_KEYS) {
        // Make it impossible to disable private keys after creation
        error = strprintf(_("Error loading %s Private keys can only be disabled during creation"), walFile);
        return nullptr;
    } else if (walInstance->IsWalFlagSet(WALLET_FLAG_DISABLE_PRIVATE_KEYS)) {
        for (auto spk_man  walInstance->GetActiveScriptPubKeyMans()) {
            if (spk_man->HavePrivateKeys()) {