{"record":{"id":"f69b5b3771ac5900","repo":"coollabsio/coolify","slug":"environment-with-the-same-name-already-exists","errorCode":null,"errorMessage":"Environment with the same name already exists.","messagePattern":"Environment with the same name already exists\\.","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"warning","filePath":"app/Livewire/Project/CloneMe.php","lineNumber":125,"sourceCode":"                if ($foundProject) {\n                    throw new \\Exception('Project with the same name already exists.');\n                }\n                $project = Project::create([\n                    'name' => $this->newName,\n                    'team_id' => currentTeam()->id,\n                    'description' => $this->project->description.' (clone)',\n                ]);\n                if ($this->environment->name !== 'production') {\n                    $project->environments()->create([\n                        'name' => $this->environment->name,\n                        'uuid' => new_public_id(),\n                    ]);\n                }\n                $environment = $project->environments->where('name', $this->environment->name)->first();\n            } else {\n                $foundEnv = $this->project->environments()->where('name', $this->newName)->first();\n                if ($foundEnv) {\n                    throw new \\Exception('Environment with the same name already exists.');\n                }\n                $project = $this->project;\n                $environment = $this->project->environments()->create([\n                    'name' => $this->newName,\n                    'uuid' => new_public_id(),\n                ]);\n            }\n            $applications = $this->environment->applications;\n            $databases = $this->environment->databases();\n            $services = $this->environment->services;\n            foreach ($applications as $application) {\n                clone_application($application, $selectedDestination, [\n                    'environment_id' => $environment->id,\n                ], $this->cloneVolumeData);\n            }\n\n            foreach ($databases as $database) {\n                $uuid = new_public_id();","sourceCodeStart":107,"sourceCodeEnd":143,"githubUrl":"https://github.com/coollabsio/coolify/blob/70b9acc42467278373e00de77abb40684e25b395/app/Livewire/Project/CloneMe.php#L107-L143","documentation":"When cloning into the same project as a new environment, Coolify checks the project's environments for the requested name and refuses duplicates - environment names are unique within a project.","triggerScenarios":"Cloning an environment using a name that already exists in the target project, e.g. cloning 'production' into a project that already has a 'production' environment.","commonSituations":"Repeated clones colliding (staging-1, staging-2...); cloning an environment back into its own project with the same name.","solutions":["Pick a fresh environment name for the clone (e.g. staging-2, review-copy)","Rename or delete the existing environment first if the clone is meant to replace it"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// inline check before submit\nif ($project->environments()->where('name', $newName)->exists()) {\n    // suggest $newName.'-'.Str::random(3)\n}","typeGuard":"function environmentNameIsFree($project, string $name): bool\n{\n    return $project->environments()->where('name', $name)->doesntExist();\n}","tryCatchPattern":null,"preventionTips":["Suggest suffixed names (staging-2, review-copy) when cloning into the same project","Delete superseded clone environments before re-cloning with the same name","Remember environments are unique per project - check the target project, not the source"],"tags":["livewire","clone","environment","duplicate-name"],"backgroundTag":"duplicate-name-conflict","analyzedSha":"70b9acc42467278373e00de77abb40684e25b395","analyzedAt":"2026-08-17T01:41:01.313Z","schemaVersion":2},"datasetVersion":"2026-08-17T04:17:16.089Z"}