After experiments, the issue is resolved by following the suggestion in the post: The issue seems caused by the bug of TFS that it is not deleted the environments totally and some dirty data is left.
Connect to TFS db
Run the following sql to check the Env data:
Select le.LabEnvironmentId from LabEnvironment le where le.PartitionId = 1 And NOT EXISTS (Select * From LabSystem ls where ls.LabEnvironmentId = le.LabEnvironmentId AND ls.PartitionId = 1)
- At last run the following sql to delete un-valid environments data:
Select le.LabEnvironmentId from LabEnvironment le where le.PartitionId = 1 And NOT EXISTS (Select * From LabSystem ls where ls.LabEnvironmentId = le.LabEnvironmentId AND ls.PartitionId = 1)
I have tested on my TFS Evn and it works.
Attention: before run the sql script, refine it carefully.