Skip to content

Migration rollback problem #2087

Open
Open
@riccardogino

Description

@riccardogino

Versions:

  • laravel-modules Version: v12.0.3
  • Laravel Version: v12.0
  • PHP Version: >=8.2

Description:

I encountered an issue where migrations fail with the error "Query without table" during rollback or reset operations.
After some debugging, I found that the root cause was that the table() method in the Migrator class returns a query builder without specifying a table if the migration table config is empty or missing.

This causes queries such as whereMigration or delete to fail because the database query has no table defined.

Steps To Reproduce:

Use laravel-modules Migrator on a Laravel 12 app with PHP >= 8.2.

Ensure that the configuration database.migrations.table is missing or empty.

Run a migration rollback or reset via the module migrator.

You will receive a "Query without table" error.

How I solved it

I updated the table() method in Migrator.php to provide a fallback table name in case the config is missing or empty:

public function table()
{
    $table = config('database.migrations.table');

    if (empty($table)) {
        $table = 'migrations';  // fallback default
    }

    return $this->laravel['db']->connection($this->database ?: null)->table($table);
}

This ensures that the query builder always has a valid table and prevents the error.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions