'run migration for different database connections

i have two mysql connection and i want to migrate specific database with php artisan migrate --database=databasename and when i ran command php artisan migrate --database=mysql_test connection that it database is different . i give error Base table or view already exists. there are two separate databases. what is the problem?

'mysql' => [
            'driver' => 'mysql',
            'url' => null,
            'host' => env('DB_HOST', '127.0.0.1'),
            'port' => env('DB_PORT', '3306'),
            'database' => "BDA",
            'username' => "root",
            'password' => "@Sina@abc123",
            'unix_socket' => env('DB_SOCKET', ''),
            'charset' => 'utf8mb4',
            'collation' => 'utf8mb4_unicode_ci',
            'prefix' => '',
            'prefix_indexes' => true,
            'strict' => false,
//            'engine' => null,
            'engine' => "InnoDB",
            'options' => extension_loaded('pdo_mysql') ? array_filter([
                PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'),
            ]) : [],
        ],
    
'mysql_test' => [
            'driver' => 'mysql',
            'url' => null,
            'host' => "127.0.0.1",
            'port' => "3306",
            'database' => "BDB",
            'username' => "root",
            'password' => "@Sina@abc123",
            'unix_socket' => env('DB_SOCKET', ''),
            'charset' => 'utf8mb4',
            'collation' => 'utf8mb4_unicode_ci',
            'prefix' => '',
            'prefix_indexes' => true,
            'strict' => false,
//            'engine' => null,
            'engine' => "InnoDB",
            'options' => extension_loaded('pdo_mysql') ? array_filter([
                PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'),
            ]) : [],
        ],


Solution 1:[1]

If you mean using a different database connection, this solution exists in the docs:

protected $connection = 'mysql_test';

add connection in migration file before up method.

Prefer Laravel doc for more info.

https://laravel.com/docs/8.x/migrations#setting-the-migration-connection

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Akash Bhalani