Skip to content

php artisan db:table command ignores configured database and uses first alphabetical database #56393

@mauricekindermann

Description

@mauricekindermann

Laravel Version

12.21.0

PHP Version

8.4.8

Database Driver & Version

MariaDB 10.5.26 for macOS (arm64) via Homebrew

Description

The php artisan db:table command does not use the configured default database in config/database.php or the DB_DATABASE environment variable. Instead, it connects to the first database alphabetically available on the database server.

This causes the command to inspect tables from the wrong database when multiple databases exist on the same server.

Expected Behavior:
The command should use the database specified in DB_DATABASE environment variable or the default connection configured in config/database.php.

Actual Behavior:
The command connects to the first database alphabetically, ignoring the Laravel database configuration.

Workaround:
You can make it work but you have to specify your full database name each time: php artisan db:table my-laravel-app.users

Steps To Reproduce

  1. Set up a database server (MySQL/MariaDB) with multiple databases
  2. Ensure one database name comes alphabetically before your Laravel app database (e.g., chirper and
    my-laravel-app)
  3. Configure your Laravel app to use the latter database via DB_DATABASE=my-laravel-app in .env
  4. Run php artisan db:table users
  5. Observe that it shows the table from the alphabetically first database (chirper) instead of the configured
    database (my-laravel-app)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions