### 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_
// B
            desc_tx->MarkDirty();
            batch.WriteTx(*desc_tx);
            MarkInputsDirty(desc_tx->tx);
            for (unsigned int i = 0; i < desc_tx->tx->vout.size(); ++i) {
                COutPoint outpoint(desc_tx->GetHash(), i);
                stdpair<TxSpendsconst_iterator, TxSpendsconst_iterator> range = mapTxSpends.equal_range(outpoint);
                for (TxSpendsconst_iterator it = range.first; it != range.second; ++it) {
                    const auto wit = mapWal.find(it->second);
                    if (wit != mapWal.end()) {
                        txs.push_back(&wit->second);
                    }
                }
            }
        }
    }
    //// 
    WalLogPrintf("AddToWal %s  %s%s\n", hash.ToString(), (fInsertedNew ? "new"  ""), (fUpdated ? "update"  ""));
    // W
    if (fInsertedNew || fUpdated)
        if (!batch.WriteTx(wtx))
            return nullptr;
    // B
    wtx.MarkDirty();
    // N
    NotifyTransactionChanged(hash, fInsertedNew ? CT_NEW  CT_UPDATED);
#if HAVE_SYSTEM
    // n
    stdstring strCmd = m_notify_tx_changed_script;
    if (!strCmd.empty())