### 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_
missingInternal = std::max(target - (int64_t)setInternalKeyPool.size(), int64_t{0});
    } else {
        missingExternal = std::max(target - (chain.nExternalChainCounter - chain.m_next_external_index), int64_t{0});
        missingInternal = std::max(target - (chain.nInternalChainCounter - chain.m_next_internal_index), int64_t{0});
    }
    if (!IsHDEnabled() || !m_storage.CanSupportFeature(FEATURE_HD_SPLIT)) {
        
        missingInternal = 0;
    }
    bool internal = false;
    WalletBatch batch(m_storage.GetDatabase());
    for (int64_t i = missingInternal + missingExternal; i--;) {
        if (i < missingInternal) {
            internal = true;
        }
        CPubKey pubkey(GenerateNewKey(batch, chain, internal));
        if (chain == m_hd_chain) {
            AddKeypoolPubkeyWithDB(pubkey, internal, batch);
        }
    }
    if (missingInternal + missingExternal > 0) {
        if (chain == m_hd_chain) {
            WalletLogPrintf("keypool added %d keys (%d internal), size=%u (%u internal)\n", missingInternal + missingExternal, missingInternal, setInternalKeyPool.size() + setExternalKeyPool.size() + set_pre_split_keypool.size(), setInternalKeyPool.size());
        } else {
            WalletLogPrintf("inactive seed with id %s added %d external keys, %d internal keys\n", HexStr(chain.seed_id), missingExternal, missingInternal);
        }
    }
    return true;
}
void LegacyScriptPubKeyMan::AddKeypoolPubkeyWithDB(const CPubKey& pubkey, const bool internal, WalletBatch& batch)