laravel/framework · error · InvalidArgumentException

The returning columns must not be empty.

Error message

The returning columns must not be empty.

What it means

insertOrIgnoreReturning() builds a RETURNING clause from $returning; an empty list would emit 'INSERT ... RETURNING' with no columns, which most engines reject. The default is ['*'], and the method explicitly guards against an explicit empty array to fail loudly rather than emit broken SQL.

Solutions

  1. Pass ['*'] (the default) when you want all columns back.
  2. List the concrete columns you need: ->insertOrIgnoreReturning($rows, ['id', 'created_at'], 'id').
  3. If you do not need any returned rows, use insertOrIgnore() instead.

Example fix

// before
->insertOrIgnoreReturning($rows, $fields, 'id')  // $fields = []

// after
->insertOrIgnoreReturning($rows, ['id'], 'id')
Defensive patterns

Strategy: validation

Validate before calling

if ($returning === []) {
    $returning = ['*'];
}
$query->insertOrIgnoreReturning($rows, $returning, $uniqueBy);

Prevention

When it happens

Trigger: ->insertOrIgnoreReturning($rows, [], 'id'), usually because the calling code computed the returning list and ended up with no columns.

Common situations: Mapping a user-supplied 'fields' parameter that resolved to nothing; refactoring a SELECT-style column list into the returning slot; copy-paste from insert() which does not take a returning argument.

Related errors


AI-assisted analysis of laravel/framework@e0f6eb3518 (2026-08-11). Data as JSON: /api/errors/0b49c6adb21acea4. Report an issue: GitHub.

Appendix: source

Thrown at src/Illuminate/Database/Query/Builder.php:4217

    /**
     * Insert new records into the database and returning specified columns with optional ignoring specific conflicts.
     *
     * @param  non-empty-array<non-empty-string>  $returning
     * @param  non-empty-string|non-empty-array<non-empty-string>|null  $uniqueBy
     * @return \Illuminate\Support\Collection
     */
    public function insertOrIgnoreReturning(array $values, array $returning = ['*'], array|string|null $uniqueBy = null)
    {
        if (empty($values)) {
            return new Collection;
        }

        if ($uniqueBy === [] || $uniqueBy === '') {
            throw new InvalidArgumentException('The unique columns must not be empty.');
        }

        if ($returning === []) {
            throw new InvalidArgumentException('The returning columns must not be empty.');
        }

        if (! is_array(array_first($values))) {
            $values = [$values];
        } else {
            foreach ($values as $key => $value) {
                ksort($value);

                $values[$key] = $value;
            }
        }

        $this->applyBeforeQueryCallbacks();

        $sql = $this->grammar->compileInsertOrIgnoreReturning($this, $values, $returning, $uniqueBy === null ? null : Arr::wrap($uniqueBy));

        $result = new Collection(
            $this->connection->selectFromWriteConnection($sql, $this->cleanBindings(Arr::flatten($values, 1)))

View on GitHub (pinned to e0f6eb3518)