Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/251.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Laravel 5 php artisan迁移--数据库参数不工作_Php_Database_Laravel_Console_Migration - Fatal编程技术网

Laravel 5 php artisan迁移--数据库参数不工作

Laravel 5 php artisan迁移--数据库参数不工作,php,database,laravel,console,migration,Php,Database,Laravel,Console,Migration,我想使用console命令迁移数据库 当我尝试php artisan migrate时,它会工作,但当我尝试php artisan migrate--database=“test”时,它会说它不工作 [InvalidArgumentException] Database [test] not configured. 怎么了?这是php artisan迁移--help Usage: migrate [options] Options: --database[=DATA

我想使用console命令迁移数据库

当我尝试
php artisan migrate
时,它会工作,但当我尝试
php artisan migrate--database=“test”
时,它会说它不工作

 [InvalidArgumentException]       
 Database [test] not configured.  
怎么了?这是php artisan迁移--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.
更新


当我意识到这不是数据库名称,而是数据库连接。。但我需要调用数据库名,因为我从另一个项目调用它来创建新数据库并迁移它。所以我需要有活力。。如何实现这一点?

您是否检查了config/database.php并查看了“connections”数组?试试这样(在我使用mysql的示例中):


在.env文件中,不应设置任何DB_uuu参数。如果使用上述设置运行php artisan migrate,它将迁移到homestead数据库。如果运行php artisan migrate--database=test,它将迁移到测试数据库。

我发现一些软件包可以完美地满足我的需要

我可以运行
migrate:tenant(连接名称)(数据库名称)
为每个租户创建数据库

env('DB_DATABASE', 'test')
这就是原因

将读取.env文件中的设置

我设定⇃.

'database' => 'test',

那么您的
test
数据库配置了吗?是的,test是我的数据库名称,如果我没有使用参数--database,它就工作了,我在我的环境中设置了
DB_database=test
我刚刚运行了
php artisan migrate
它工作了正如我上面描述的,我意识到这是一个数据库连接,所以我需要创建一个新的连接。。但现在的问题是,这是SaaS,每个租户都有自己的数据库设置。因此,如果我有很多租户,就不可能使用这个解决方案。也许值得在谷歌上快速浏览一下,因为已经有很多关于SaaS和Laravel的问题了——我发现这似乎更符合你的要求!好的,经过更多的研究,我发现了这个感谢您的帮助谢谢您分享关于我创建的软件包的消息。:)
'database' => 'test',