spatie/laravel-permission · warning
Setup teams migration already exists. Following file was fou
Error message
Setup teams migration already exists. Following file was found:
What it means
Before generating the teams migration, permission:setup-teams globs database/migrations for any file matching *add_teams_fields.php. If one or more exist, it prints this warning listing them (singular or plural wording depending on the count) and then asks 'Proceed with the migration creation?'. Confirming would create a duplicate migration, so the intended action is to decline — the existing migration already adds the teams fields.
Source
Thrown at src/Commands/UpgradeForTeamsCommand.php:33
public function handle(): int
{
if (! Config::get('permission.teams')) {
$this->error('Teams feature is disabled in your permission.php file.');
$this->warn('Please enable the teams setting in your configuration.');
return self::FAILURE;
}
$this->line('');
$this->info('The teams feature setup is going to add a migration and a model');
$existingMigrations = $this->alreadyExistingMigrations();
if ($existingMigrations) {
$this->line('');
$this->warn($this->getExistingMigrationsWarning($existingMigrations));
}
$this->line('');
if (! $this->confirm('Proceed with the migration creation?', true)) {
return self::SUCCESS;
}
$this->line('');
$this->line('Creating migration');
if ($this->createMigration()) {
$this->info('Migration created successfully.');
} else {
$this->error(
"Couldn't create migration.\n".
'Check the write permissions within the database/migrations directory.'View on GitHub (pinned to afd24018f6)
Solutions
- Answer 'no' at the 'Proceed with the migration creation?' prompt — the listed migration already sets up teams fields
- If the existing migration is unwanted (never run, wrong content), delete the listed file from database/migrations and re-run the command
- If duplicate migrations already shipped, keep exactly one *add_teams_fields.php, delete the other, and check php artisan migrate:status for consistency
- Make scripts idempotent: only run the command when ls database/migrations/*add_teams_fields.php finds nothing
Example fix
# before — deploy script runs it every time php artisan permission:setup-teams # warns: Setup teams migration already exists. # after — skip when the migration already exists ls database/migrations/*add_teams_fields.php >/dev/null 2>&1 \ || php artisan permission:setup-teams
Defensive patterns
Strategy: validation
Validate before calling
// run the setup only when no teams migration exists yet
$existing = glob(database_path('migrations/*add_teams_fields.php'));
if (empty($existing)) {
\Illuminate\Support\Facades\Artisan::call('permission:setup-teams');
} else {
// migration already present — nothing to generate
} Prevention
- Run permission:setup-teams once per project and commit the generated *add_teams_fields.php migration
- Guard automated runs with a file-existence check on database/migrations/*add_teams_fields.php
- After any warning about duplicates, inspect php artisan migrate:status and remove the extra migration before deploying
When it happens
Trigger: Running `php artisan permission:setup-teams` a second time in the same project; running it after pulling a branch where a teammate already committed the *add_teams_fields.php migration; CI or provisioning scripts that invoke the command unconditionally on every run.
Common situations: A deploy pipeline calls permission:setup-teams idempotently without checking the filesystem; the command was run once, output not committed, and another developer runs it again; a first run created the file but the migration was never executed, so the developer retried the command.
Related errors
- Please enable the teams setting in your configuration.
- Teams feature disabled, argument --team-id has no effect. Ei
- Teams feature disabled, argument --team-id has no effect. Ei
- Role `{$role->name}` already exists on the global team; argu
- Unsupported type for $roles parameter to hasRole().
AI-assisted analysis of spatie/laravel-permission@afd24018f6 (2026-08-21).
Data as JSON: /api/errors/21ce2be2c00f5d41.
Report an issue: GitHub.