Setting the parent of a transform which resides in a prefab error

I’m getting the following error:

“Setting the parent of a transform which resides in a prefab is disabled to prevent data corruption.”

ON the following bit of code:

public void GenerateSectors() {
		
		ClearLocations();
		GameObject locationPrefab = GameObject.CreatePrimitive(PrimitiveType.Cube);
		locationPrefab.AddComponent("Location");
		
		for (int i = 0; i < numberOfLocations; i++) {
			Vector3 rand = Random.insideUnitSphere * 90f;
			rand.y = 0.0f;
			
			
			GameObject newLocation = (GameObject)Instantiate(locationPrefab, rand, Quaternion.identity);
			
			newLocation.transform.parent = mapParent.transform;
			locations.Add(newLocation.transform);
			
		}
		
		Destroy(locationPrefab);
	}

I have searched the internet and the forums for an answer as to why this is happening. AND I have found several people who encountered a similar problem. I believe I Have made the needed changes to my code so it would work (according to information found through searching.) but alas, I have been unsuccessful.

I’m trying to create a bunch of cubes, set their parent to a predefined object, and add them to a list so I can manipulate and destroy them later.

facing the same problem , am pretty damn sure there is nothing wrong with the code , for instance i am instantiating two objects in a scene with the same way , one is working fine and assigned to the right parent the other is not and getting this error