yiisoft/yii2 · error · yii\base\InvalidArgumentException

Relation names are case sensitive. {class} has a relation na

Error message

Relation names are case sensitive. {class} has a relation named "{realName}" instead of "{name}".

What it means

Error "Relation names are case sensitive. {class} has a relation named "{realName}" instead of "{name}"." thrown in yiisoft/yii2.

Source

Thrown at framework/db/BaseActiveRecord.php:1281

            }

            return null;
        }
        if (!$relation instanceof ActiveQueryInterface) {
            if ($throwException) {
                throw new InvalidArgumentException(get_class($this) . ' has no relation named "' . $name . '".');
            }

            return null;
        }

        if (method_exists($this, $getter)) {
            // relation name is case sensitive, trying to validate it when the relation is defined within this class
            $method = new \ReflectionMethod($this, $getter);
            $realName = lcfirst(substr($method->getName(), 3));
            if ($realName !== $name) {
                if ($throwException) {
                    throw new InvalidArgumentException('Relation names are case sensitive. ' . get_class($this) . " has a relation named \"$realName\" instead of \"$name\".");
                }

                return null;
            }
        }

        return $relation;
    }

    /**
     * Establishes the relationship between two models.
     *
     * The relationship is established by setting the foreign key value(s) in one model
     * to be the corresponding primary key value(s) in the other model.
     * The model with the foreign key will be saved into database **without** performing validation
     * and **without** events/behaviors.
     *
     * If the relationship involves a junction table, a new row will be inserted into the

View on GitHub (pinned to 66f00d18a2)

When it happens

Trigger: Thrown at framework/db/BaseActiveRecord.php:1281 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of yiisoft/yii2@66f00d18a2 (2026-08-17). Data as JSON: /api/errors/a81a04c61cae90db. Report an issue: GitHub.