cakephp/cakephp · error · RuntimeException

" " is not a valid index option.

Error message

"%s" is not a valid index option.

What it means

Index::setAttributes() validates each key of the attributes array against a whitelist: columns, type, name, length, order, include, where, accessMethod. Any other key throws RuntimeException naming the offending attribute, preventing silently ignored index options.

Solutions

  1. Fix the attribute name to one of: columns, type, name, length, order, include, where, accessMethod
  2. Use ['type' => 'unique'] instead of a 'unique' key for unique indexes
  3. Validate dynamically-built attribute arrays against the whitelist before calling setAttributes

Example fix

// before
$index->setAttributes(['column' => ['user_id']]);
// after
$index->setAttributes(['columns' => ['user_id']]);
Defensive patterns

Strategy: validation

Validate before calling

$valid = ['columns','type','name','length','order','include','where','accessMethod'];
$bad = array_diff(array_keys($attrs), $valid);
if ($bad) { throw new InvalidArgumentException('Unknown index options: ' . implode(',', $bad)); }
$index->setAttributes($attrs);

Try / catch

try {
    $index->setAttributes($attrs);
} catch (\RuntimeException $e) {
    throw new ConfigException('Bad index option: ' . $e->getMessage(), 0, $e);
}

Prevention

When it happens

Trigger: Calling $table->addIndex(...)->setAttributes(['column' => ['x']]) (singular 'column' instead of 'columns'), or passing options like 'unique' or 'uniqueIndex' that belong elsewhere (the type option).

Common situations: Typo in index option names; passing column-level options (like 'default') to an index; migrating config from another tool with different index option vocabulary.

Understand the failure class

Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.

Related errors


AI-assisted analysis of cakephp/cakephp@1128eba9b0 (2026-09-12). Data as JSON: /api/errors/5f9f48e9d6ee5e50. Report an issue: GitHub.

Appendix: source

Thrown at src/Database/Schema/Index.php:309

    public function getAccessMethod(): ?string
    {
        return $this->accessMethod;
    }

    /**
     * Utility method that maps an array of index options to this object's methods.
     *
     * @param array<string, mixed> $attributes Attributes to set.
     * @throws \RuntimeException
     * @return $this
     */
    public function setAttributes(array $attributes)
    {
        // Valid Options
        $validOptions = ['columns', 'type', 'name', 'length', 'order', 'include', 'where', 'accessMethod'];
        foreach ($attributes as $attr => $value) {
            if (!in_array($attr, $validOptions, true)) {
                throw new RuntimeException(sprintf('"%s" is not a valid index option.', $attr));
            }
            $method = 'set' . ucfirst($attr);
            $this->$method($value);
        }

        return $this;
    }

    /**
     * Convert an index into an array that is compatible with the Index constructor.
     *
     * @return array<string, mixed>
     */
    public function toArray(): array
    {
        $result = [
            'name' => $this->getName(),
            'columns' => $this->getColumns(),

View on GitHub (pinned to 1128eba9b0)