我想使用控制台命令迁移数据库。
当我尝试时,php artisan migrate是工作的,但当我尝试时,php artisan migrate --database="test"是不工作的,它说
[InvalidArgumentException]
Database [test] not configured. 怎么了?我是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.更新
当我意识到这不是数据库名而是数据库连接..。但是我需要调用数据库名,因为我从另一个项目调用它来创建新的数据库并迁移它。所以我需要充满活力..。如何做到这一点?
发布于 2016-06-15 13:34:27
我找到了一些我需要的东西。
https://packagist.org/packages/a2way/laravel-tenant-migrate
我可以运行migrate:tenant (connection-name) (database-name)为每个租户创建数据库。
发布于 2016-06-15 11:30:34
您检查了config/database.php并查看了“connections”数组吗?尝试这样的方法(在我使用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,
],
],在.env文件中,不应该设置任何DB_参数。如果您使用上面的设置运行php迁移,它将迁移到above数据库。如果您运行php
发布于 2021-02-09 10:33:44
env('DB_DATABASE', 'test')这就是原因。
读取.env文件中的设置。
我设定了⇃。
'database' => 'test',https://stackoverflow.com/questions/37833327
复制相似问题