Hi,
I just wanted to add something to this topic as I had the same error but the fix was slightly different, although adding files to the database was the key.
The error I received was:
An error occurred while processing 'AltFile' metadata for database id 8, file id 3, and transaction='alterdb'.
Upon reviewing the sys.sysfiles for the database (id=8) it was obvious that there was no fileid=3. There was a 1, 2, 4, 5, 6 but no 3.
There were two filegroups: PRIMARY had 1 file, with a fileid=1, and the SECONDARY had three files, fileid=4,5 & 6.
I suspect there was a second file in the PRIMARY filegroup at some stage with a fileid=3 which was removed, thus leaving a hole in the sequence.
The solution was to add a file to the PRIMARY filegroup, confirm that the file was created with a fileid=3 and re-run the ALTER DATABASE command, this time it worked fine.
Just wanted to share that with the community.
Thanks
Paul