Snap: How to force a rebuild of the file database after files have been removed server-side?

I used an old HDD to set up a Nextcloud instance via snap. It performed well, but the disk crashed and an attempt to rescue it is underway. I have swapped the drive with another model, and have changed my config.php file to point to the new location. I manually created the .ocdata file by running touch .ocdata in the data directory.
I can now log onto the browser interface (but my iPhone is giving me trouble by repeatedly asking for a password and refusing to upload anything).
However, Nextcloud seems to be storing a database of files somewhere outside the data directory I specified within config.php. When I log onto the web interface, I am greeted by a list of files that no longer exist (as they were not copied to the new hard drive), and opening them naturally produces an error.

I have already tried running
sudo nextcloud.occ files:scan --all
but for each user in the system I get the message: “Home storage for user x not writable. Make sure you’re running the scan command only as the user the web server runs as.”

I’ve also ran
sudo nextcloud.occ maintenance:repair
but the command only returns a bullet point list of things it has not done (along the lines of “0 files” or “nothing to do”).

How do I reset this database and force a re-scan of the files present in the data directory?

Thank you for your help!

I have opened a github issue to try and get some help on the matter, but have managed to solve this myself after more than two weeks of trying various things. Database won't remove files missing from data directory · Issue #1684 · nextcloud/nextcloud-snap · GitHub

Tl;dr: Nextcloud does not automatically create user folders, and further more, the “user home folder” isn’t the folder named after the user, but a subfolder named “files”; E.g. the home folder of user “anon” is in “data/anon/files/”.

You have to manually mkdir the user folders as well as the “files” folders if you swap hard drives or otherwise delete these folders.