laravel/framework · error · InvalidArgumentException

Morph key type must be 'int', 'uuid', or 'ulid'.

Error message

Morph key type must be 'int', 'uuid', or 'ulid'.

What it means

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).

Source

Thrown at src/Illuminate/Database/Schema/Builder.php:99

     * Set the default time precision for migrations.
     */
    public static function defaultTimePrecision(?int $precision): void
    {
        static::$defaultTimePrecision = $precision;
    }

    /**
     * Set the default morph key type for migrations.
     *
     * @param  string  $type
     * @return void
     *
     * @throws \InvalidArgumentException
     */
    public static function defaultMorphKeyType(string $type)
    {
        if (! in_array($type, ['int', 'uuid', 'ulid'])) {
            throw new InvalidArgumentException("Morph key type must be 'int', 'uuid', or 'ulid'.");
        }

        static::$defaultMorphKeyType = $type;
    }

    /**
     * Set the default morph key type for migrations to UUIDs.
     *
     * @return void
     */
    public static function morphUsingUuids()
    {
        static::defaultMorphKeyType('uuid');
    }

    /**
     * Set the default morph key type for migrations to ULIDs.
     *

View on GitHub (pinned to bd6b5437e6)

Solutions

  1. Pass exactly 'int', 'uuid', or 'ulid' (lowercase).
  2. For UUID use the helper morphUsingUuids(); for ULID use morphUsingUlid()s; for int use morphUsingInts().
  3. Double-check the value against the allowed list before calling.

Example fix

// before
Schema::defaultMorphKeyType('UUID');

// after
Schema::defaultMorphKeyType('uuid');
// or equivalently:
Schema::morphUsingUuids();
Defensive patterns

Strategy: validation

Validate before calling

$type = 'uuid';
if (! in_array($type, ['int','uuid','ulid'], true)) {
    throw new \InvalidArgumentException("Morph key type must be 'int', 'uuid', or 'ulid'; got '{$type}'.");
}
Schema::defaultMorphKeyType($type);

Type guard

function isValidMorphKeyType(string $type): bool
{
    return in_array($type, ['int','uuid','ulid'], true);
}

Prevention

When it happens

Trigger: 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').

Common situations: 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.

Related errors


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