doctrine/orm · error · InvalidArgumentException

%s(): The alias for entity %s must not be omitted.

Error message

%s(): The alias for entity %s must not be omitted.

What it means

delete($delete, $alias) switches the builder to a bulk DELETE and, when an entity name is given, registers it as a FROM expression, which in DQL always needs an alias. The builder cannot invent one for you, so omitting the second argument throws InvalidArgumentException immediately. Calling delete() with no arguments is legal and only sets the statement type.

Source

Thrown at src/QueryBuilder.php:781

     *         ->where('u.id = :user_id')
     *         ->setParameter('user_id', 1);
     * </code>
     *
     * @param class-string|null $delete The class/type whose instances are subject to the deletion.
     * @param string|null       $alias  The class/type alias used in the constructed query.
     *
     * @return $this
     */
    public function delete(string|null $delete = null, string|null $alias = null): static
    {
        $this->type = QueryType::Delete;

        if (! $delete) {
            return $this;
        }

        if (! $alias) {
            throw new InvalidArgumentException(sprintf(
                '%s(): The alias for entity %s must not be omitted.',
                __METHOD__,
                $delete,
            ));
        }

        return $this->add('from', new Expr\From($delete, $alias));
    }

    /**
     * Turns the query being built into a bulk update query that ranges over
     * a certain entity type.
     *
     * <code>
     *     $qb = $em->createQueryBuilder()
     *         ->update('User', 'u')
     *         ->set('u.password', '?1')
     *         ->where('u.id = ?2');

View on GitHub (pinned to d9b9ff7301)

Solutions

  1. Pass the alias: $qb->delete(User::class, 'u').
  2. Or split the calls: $qb->delete()->from(User::class, 'u').

Example fix

// before
$qb = $em->createQueryBuilder()->delete(User::class); // InvalidArgumentException

// after
$qb = $em->createQueryBuilder()->delete(User::class, 'u');
Defensive patterns

Strategy: validation

Validate before calling

// wrapper that makes the alias mandatory-by-default at your call sites
public function bulkDelete(string $entity, string $alias = 'e'): QueryBuilder
{
    return $this->em->createQueryBuilder()->delete($entity, $alias);
}

Prevention

When it happens

Trigger: $qb->delete(User::class) with the alias omitted; $qb->delete(User::class, null) explicitly; translating a DQL string like 'DELETE FROM User u' into builder calls and dropping the alias.

Common situations: Refactoring raw DQL to QueryBuilder; code generators that skip optional-looking parameters; copy-paste from select()-style examples.

Understand the failure class

Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.

Related errors


AI-assisted analysis of doctrine/orm@d9b9ff7301 (2026-08-21). Data as JSON: /api/errors/9e2a64a02fbc4456. Report an issue: GitHub.