{"id":"5e23800c479f7315","repo":"laravel/framework","slug":"morph-key-type-must-be-int-uuid-or-ulid","errorCode":null,"errorMessage":"Morph key type must be 'int', 'uuid', or 'ulid'.","messagePattern":"Morph key type must be 'int', 'uuid', or 'ulid'\\.","errorType":"exception","errorClass":"InvalidArgumentException","httpStatus":null,"severity":"error","filePath":"src/Illuminate/Database/Schema/Builder.php","lineNumber":99,"sourceCode":"     * Set the default time precision for migrations.\n     */\n    public static function defaultTimePrecision(?int $precision): void\n    {\n        static::$defaultTimePrecision = $precision;\n    }\n\n    /**\n     * Set the default morph key type for migrations.\n     *\n     * @param  string  $type\n     * @return void\n     *\n     * @throws \\InvalidArgumentException\n     */\n    public static function defaultMorphKeyType(string $type)\n    {\n        if (! in_array($type, ['int', 'uuid', 'ulid'])) {\n            throw new InvalidArgumentException(\"Morph key type must be 'int', 'uuid', or 'ulid'.\");\n        }\n\n        static::$defaultMorphKeyType = $type;\n    }\n\n    /**\n     * Set the default morph key type for migrations to UUIDs.\n     *\n     * @return void\n     */\n    public static function morphUsingUuids()\n    {\n        static::defaultMorphKeyType('uuid');\n    }\n\n    /**\n     * Set the default morph key type for migrations to ULIDs.\n     *","sourceCodeStart":81,"sourceCodeEnd":117,"githubUrl":"https://github.com/laravel/framework/blob/bd6b5437e6ad87bb49f9b426724f07a9f64e9683/src/Illuminate/Database/Schema/Builder.php#L81-L117","documentation":"Schema\\Builder::defaultMorphKeyType() throws InvalidArgumentException when the type is not one of 'int', 'uuid', or 'ulid'. Polymorphic morph columns store the related model's key type, and Laravel only supports those three key shapes for morph maps. The static default is checked at configuration time (typically in a service provider or AppServiceProvider boot).","triggerScenarios":"Calling Schema::defaultMorphKeyType($type) or Relation::defaultMorphKeyType($type) with a value outside ['int','uuid','ulid'] (e.g. 'bigInt', 'string', 'guid', or a typo like 'UUID').","commonSituations":"Migrating to UUID/ULID morph keys and passing the wrong string. Typos or case mismatches in the type argument. Copying example code that uses a non-canonical key type name.","solutions":["Pass exactly 'int', 'uuid', or 'ulid' (lowercase).","For UUID use the helper morphUsingUuids(); for ULID use morphUsingUlid()s; for int use morphUsingInts().","Double-check the value against the allowed list before calling."],"exampleFix":"// before\nSchema::defaultMorphKeyType('UUID');\n\n// after\nSchema::defaultMorphKeyType('uuid');\n// or equivalently:\nSchema::morphUsingUuids();","handlingStrategy":"validation","validationCode":"$type = 'uuid';\nif (! in_array($type, ['int','uuid','ulid'], true)) {\n    throw new \\InvalidArgumentException(\"Morph key type must be 'int', 'uuid', or 'ulid'; got '{$type}'.\");\n}\nSchema::defaultMorphKeyType($type);","typeGuard":"function isValidMorphKeyType(string $type): bool\n{\n    return in_array($type, ['int','uuid','ulid'], true);\n}","tryCatchPattern":null,"preventionTips":["Use the dedicated helpers morphUsingUuids()/morphUsingUlid()/morphUsingInts() instead of the raw string.","Set the morph key type once in AppServiceProvider::boot().","Validate any externally sourced type string before passing it in."],"tags":["morph","schema","validation","uuid","ulid"],"analyzedSha":"bd6b5437e6ad87bb49f9b426724f07a9f64e9683","analyzedAt":"2026-08-06T00:28:32.783Z","schemaVersion":2}