laravel/framework · error · InvalidArgumentException

The --model and --except options cannot be combined.

Error message

The --model and --except options cannot be combined.

What it means

Thrown by PruneCommand::models() when the artisan model:prune command is invoked with both --model and --except at the same time. The two flags are mutually exclusive ways to scope which models get pruned; combining them is ambiguous.

Source

Thrown at src/Illuminate/Database/Console/PruneCommand.php:124

        if ($total == 0) {
            $this->components->info("No prunable [$model] records found.");
        }
    }

    /**
     * Determine the models that should be pruned.
     *
     * @return \Illuminate\Support\Collection
     *
     * @throws \InvalidArgumentException
     */
    protected function models()
    {
        $models = $this->option('model');
        $except = $this->option('except');

        if ($models && $except) {
            throw new InvalidArgumentException('The --model and --except options cannot be combined.');
        }

        if ($models) {
            return (new Collection($models))
                ->filter(static fn (string $model) => class_exists($model))
                ->values();
        }

        return (new Collection(Finder::create()->in($this->getPath())->files()->name('*.php')))
            ->map(function ($model) {
                $namespace = $this->laravel->getNamespace();

                return $namespace.str_replace(
                    ['/', '.php'],
                    ['\\', ''],
                    Str::after($model->getRealPath(), realpath(app_path()).DIRECTORY_SEPARATOR)
                );
            })

View on GitHub (pinned to bd6b5437e6)

Solutions

  1. Use only --model to prune an explicit list, or only --except to prune all-but-a-list.
  2. If you need 'everything except X', drop --model and keep --except.
  3. If you need a specific subset, list it fully with --model and omit --except.
  4. Inspect the command help: php artisan model:prune -h to confirm mutually exclusive options.

Example fix

# before
php artisan model:prune --model="App\Models\Post" --except="App\Models\Draft"

# after
php artisan model:prune --except="App\Models\Draft"
Defensive patterns

Strategy: validation

Validate before calling

if (! empty($modelOption) && ! empty($exceptOption)) {
    throw new \InvalidArgumentException('Pass either --model or --except, not both.');
}

Prevention

When it happens

Trigger: Running `php artisan model:prune --model=App\Models\Post --except=App\Models\Draft`. The command parses both options, sees they are both truthy, and throws InvalidArgumentException before scanning.

Common situations: Copy-pasting flags from different invocations; scripting a cron job that layers both options; shell glob/alias accidentally appending --except.

Related errors


AI-assisted analysis of laravel/framework@bd6b5437e6 (2026-08-06). Data as JSON: /data/errors/3df4a7b3bc63d0bd.json. Report an issue: GitHub.