{"record":{"id":"21ce2be2c00f5d41","repo":"spatie/laravel-permission","slug":"setup-teams-migration-already-exists-following-fi","errorCode":null,"errorMessage":"Setup teams migration already exists.\nFollowing file was found: ","messagePattern":"Setup teams migration already exists\\.\nFollowing file was found: ","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"src/Commands/UpgradeForTeamsCommand.php","lineNumber":33,"sourceCode":"\n    public function handle(): int\n    {\n        if (! Config::get('permission.teams')) {\n            $this->error('Teams feature is disabled in your permission.php file.');\n            $this->warn('Please enable the teams setting in your configuration.');\n\n            return self::FAILURE;\n        }\n\n        $this->line('');\n        $this->info('The teams feature setup is going to add a migration and a model');\n\n        $existingMigrations = $this->alreadyExistingMigrations();\n\n        if ($existingMigrations) {\n            $this->line('');\n\n            $this->warn($this->getExistingMigrationsWarning($existingMigrations));\n        }\n\n        $this->line('');\n\n        if (! $this->confirm('Proceed with the migration creation?', true)) {\n            return self::SUCCESS;\n        }\n\n        $this->line('');\n\n        $this->line('Creating migration');\n\n        if ($this->createMigration()) {\n            $this->info('Migration created successfully.');\n        } else {\n            $this->error(\n                \"Couldn't create migration.\\n\".\n                'Check the write permissions within the database/migrations directory.'","sourceCodeStart":15,"sourceCodeEnd":51,"githubUrl":"https://github.com/spatie/laravel-permission/blob/afd24018f68306e8b43ace487c107a59af1be776/src/Commands/UpgradeForTeamsCommand.php#L15-L51","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"# before — deploy script runs it every time\nphp artisan permission:setup-teams  # warns: Setup teams migration already exists.\n\n# after — skip when the migration already exists\nls database/migrations/*add_teams_fields.php >/dev/null 2>&1 \\\n  || php artisan permission:setup-teams","handlingStrategy":"validation","validationCode":"// run the setup only when no teams migration exists yet\n$existing = glob(database_path('migrations/*add_teams_fields.php'));\nif (empty($existing)) {\n    \\Illuminate\\Support\\Facades\\Artisan::call('permission:setup-teams');\n} else {\n    // migration already present — nothing to generate\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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"],"tags":["laravel","artisan","migration","spatie-permission","teams","idempotency"],"backgroundTag":"migration-already-exists","analyzedSha":"afd24018f68306e8b43ace487c107a59af1be776","analyzedAt":"2026-08-21T01:13:42.706Z","schemaVersion":2},"datasetVersion":"2026-08-21T03:17:12.404Z"}