简体   繁体   English

Laravel 5 php artisan migrate --database 参数不起作用

[英]Laravel 5 php artisan migrate --database parameter not working

i want to migrate database using console command我想使用控制台命令迁移数据库

when i try php artisan migrate is working, but when i try php artisan migrate --database="test" is not working it said当我尝试php artisan migrate工作时,但当我尝试php artisan migrate --database="test"它说

 [InvalidArgumentException]       
 Database [test] not configured.  

what's wrong ?怎么了? this is php artisan migrate --help这是php artisan migrate --help

 Usage:
 migrate [options]

Options:
--database[=DATABASE]  The database connection to use.
--force                Force the operation to run when in production.
--path[=PATH]          The path of migrations files to be executed.
--pretend              Dump the SQL queries that would be run.
--seed                 Indicates if the seed task should be re-run.
-h, --help                 Display this help message
-q, --quiet                Do not output any message
-V, --version              Display this application version
--ansi                 Force ANSI output
--no-ansi              Disable ANSI output
-n, --no-interaction       Do not ask any interactive question
--env[=ENV]            The environment the command should run under.

UPDATE更新

after i realise it's not database name, but database connection.. but i need to call database name, because i call this from another project to create new database and migrate it.在我意识到它不是数据库名称,而是数据库连接之后......但我需要调用数据库名称,因为我从另一个项目调用它来创建新数据库并迁移它。 so i need to be dynamic.. how to achieve that ?所以我需要动态..如何实现?

Have you checked config/database.php and look at the 'connections' array?您是否检查了 config/database.php 并查看了“connections”数组? Try something like this (In the example I'm using mysql):尝试这样的事情(在我使用 mysql 的例子中):

'connections' => [

        // Replace mysql with your DB driver
        'mysql' => [
            'driver'    => 'mysql',
            'host'      => env('DB_HOST', 'localhost'),
            'database'  => env('DB_DATABASE', 'homestead'),
            'username'  => env('DB_USERNAME', 'homestead'),
            'password'  => env('DB_PASSWORD', 'secret'),
            'charset'   => 'utf8',
            'collation' => 'utf8_unicode_ci',
            'prefix'    => '',
            'strict'    => false,
        ],

        'test' => [
            'driver'    => 'mysql',
            'host'      => env('DB_HOST', 'localhost'),
            'database'  => env('DB_DATABASE', 'test'),
            'username'  => env('DB_USERNAME', 'homestead'),
            'password'  => env('DB_PASSWORD', 'secret'),
            'charset'   => 'utf8',
            'collation' => 'utf8_unicode_ci',
            'prefix'    => '',
            'strict'    => false,
        ],


    ],

In your .env file, you shouldn't have any DB_ parameters set.在您的 .env 文件中,您不应设置任何 DB_ 参数。 If you run php artisan migrate with the above setup, it will migrate to the homestead database.如果您使用上述设置运行 php artisan migrate,它将迁移到 homestead 数据库。 If you run php artisan migrate --database=test, it will migrate to the test database.如果您运行 php artisan migrate --database=test,它将迁移到测试数据库。

I found some package that working perfectly what i need..我发现了一些可以完美满足我需要的包。

https://packagist.org/packages/a2way/laravel-tenant-migrate https://packagist.org/packages/a2way/laravel-tenant-migrate

i can run migrate:tenant (connection-name) (database-name) for create database for every tenant..我可以运行migrate:tenant (connection-name) (database-name)为每个租户创建数据库..

env('DB_DATABASE', 'test')

This is the cause.这就是原因。

The settings in the .env file are read.读取 .env 文件中的设置。

I set ⇃.我设置了⇃。

'database' => 'test',

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM