coollabsio/coolify · error · Exception
You cannot delete this GitHub App because it is in use by {a
Error message
You cannot delete this GitHub App because it is in use by {applications_count} application(s). Delete them first. What it means
Thrown from a model deleting hook registered in GithubApp::booted() (app/Models/GithubApp.php:49). Coolify refuses to delete a GitHub App source while any Application row still references it via source_id, because deleting it would orphan the apps' Git integration. The same hook also cascades deletion of the app's PrivateKey, but only when that key is not used by any server, other application, or other Git app — the guard runs before any of that happens.
Source
Thrown at app/Models/GithubApp.php:49
protected $appends = ['type'];
protected $casts = [
'is_public' => 'boolean',
'is_system_wide' => 'boolean',
'type' => 'string',
];
protected $hidden = [
'client_secret',
'webhook_secret',
];
protected static function booted(): void
{
static::deleting(function (GithubApp $github_app) {
$applications_count = Application::where('source_id', $github_app->id)->count();
if ($applications_count > 0) {
throw new \Exception('You cannot delete this GitHub App because it is in use by '.$applications_count.' application(s). Delete them first.');
}
$privateKey = $github_app->privateKey;
if ($privateKey) {
// Check if key is used by anything EXCEPT this GitHub app
$isUsedElsewhere = $privateKey->servers()->exists()
|| $privateKey->applications()->exists()
|| $privateKey->githubApps()->where('id', '!=', $github_app->id)->exists()
|| $privateKey->gitlabApps()->exists();
if (! $isUsedElsewhere) {
$privateKey->delete();
} else {
}
}
});
}
View on GitHub (pinned to 70b9acc424)
Solutions
- Delete (or move to another source) every application that uses this GitHub App first: run Application::where('source_id', $githubApp->id)->get() and handle each one.
- If apps must keep deploying, point them at a different/other source (update source_id) instead of deleting the app.
- Retry $githubApp->delete() once the count is zero — the private-key cascade then runs automatically.
- In shared instances, search all teams/projects for apps referencing the source, not just the project you are looking at.
Example fix
// before
$githubApp->delete(); // throws if any app still uses it
// after — guard the delete with a precheck and clear dependents
$inUse = Application::where('source_id', $githubApp->id)->pluck('name');
if ($inUse->isNotEmpty()) {
throw new \Exception('Cannot delete: still used by '.$inUse->implode(', '));
}
$githubApp->delete(); Defensive patterns
Strategy: validation
Validate before calling
// Before deleting a GitHub App, check for dependents
$inUse = Application::where('source_id', $githubApp->id)->exists();
if ($inUse) {
// delete or re-point those applications first
} Try / catch
try {
$githubApp->delete();
} catch (\Exception $e) {
if (str_contains($e->getMessage(), 'in use by')) {
$count = Application::where('source_id', $githubApp->id)->count();
return "Delete blocked: {$count} application(s) still use this GitHub App.";
}
throw $e;
} Prevention
- Always resolve dependents before deleting Git sources; the count in the message tells you how many remain.
- When migrating auth, re-point applications to the new source instead of deleting the old one first.
- In cleanup scripts, delete applications before their sources, never the reverse order.
When it happens
Trigger: Calling $githubApp->delete() (the UI 'Delete' action on a GitHub source under Security → GitHub Apps) while Application::where('source_id', $github_app->id)->count() > 0. Any single application created from that GitHub App — including deleted-but-not-purged or preview-environment apps — triggers it.
Common situations: Cleaning up unused Git sources during an org restructure while apps still point at them; bulk scripts that delete sources before apps; forgetting that an old app in another project/environment still uses the source; teams migrated off a GitHub App to a different auth method without editing every app's source.
Related errors
- This source is being used by an application. Please delete a
- Pre-deployment command: Could not find a valid container. Is
- Post-deployment command: Could not find a valid container. I
- 69420
- ScheduledTaskJob failed: No valid container was found. Is th
AI-assisted analysis of coollabsio/coolify@70b9acc424 (2026-08-17).
Data as JSON: /api/errors/141362526f531c2e.
Report an issue: GitHub.