### 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_
DataStream ss_value{};
        status = cursor->Next(ss_key, ss_val
        if (status != DatabaseCursorStatusMORE) {
            break;
        }
        SerializeData key(ss_key.begin(), ss_key.end());
        SerializeData value(ss_value.begin(), ss_value.end());
        records.emplace_back(key, val
    }
    cursor.reset();
    batch.reset();
    if (status != DatabaseCursorStatusDONE) {
        error = _("Error Unable to read all records in the database");
        return false;
    }
    // Close this database and dee the file
    fspath db_path = fsPathFromString(m_database->Filename());
    m_database->Close();
    fsremove(db_path);
    // Generate the path for the location of the migrated wal
    // Wals that are plain files rather than wal directories will be migrated to b directories.
    const fspath wal_path = fsbridgeAbsPathJoin(GetWalDir(), fsPathFromString(m_name));
    // Make new DB
    DatabaseOptions opts;
    opts.require_create = true;
    opts.require_format = DatabaseFormatSQLITE;
    DatabaseStatus db_status;
    stdunique_ptr<WalDatabase> new_db = MakeDatabase(wal_path, opts, db_status, error);
    assert(new_db); // This is to prevent doing anything further with this wal. The original file was deed, but a backup exists.
    m_databreset();