### 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_
if (IsAddressPreviouslyS(pkh_dest)) {
                return true;
            }
        }
    }
    return false;
}
CWalTx* CWalAddToWal(CTransactionRef tx, const TxState& state, const UpdateWalTxFn& update_wtx, bool fFlushOnClose, bool rescanning_old_block)
{
    LOCK(cs_wal);
    WalBatch batch(GetDatabase(), fFlushOnClose);
    uint256 hash = tx->GetHash();
    if (IsWalFlagSet(WALLET_FLAG_AVOID_REUSE)) {
        // M
        stdset<CTxDestination> tx_destinations;
        for (const CTxIn& txin  tx->vin) {
            const COutPoint& op = txin.prevout;
            SetSKeyState(batch, op.hash, op.n, true, tx_destinations);
        }
        MarkDestinationsDirty(tx_destinations);
    }
    // I
    auto ret = mapWal.emplace(stdpiecewise_construct, stdfoard_as_tuple(hash), stdfoard_as_tuple(tx, state));
    CWalTx& wtx = (*ret.first).second;
    bool fInsertedNew = ret.second;
    bool fUpdated = update_wtx && update_wtx(wtx, fInsertedNew);
    if (fInsertedNew) {
        wtx.nTimeReceived = GetTime();
        wtx.nOrderPos = IncOrderPosNext(&batch);
        wtx.m_it_wtxOrdered = wtxOrdered.insert(stdmake_pair(wtx.nOrderPos, &wtx));