我想使用控制台命令迁移数据库
当我尝试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.
更新
在我意识到这不是数据库名称,而是数据库连接之后..但我需要调用数据库名称,因为我从另一个项目调用它来创建新数据库并迁移它。所以我需要充满活力......如何实现这一目标?
最佳答案
您检查过 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 artisan migrate,它将迁移到 homestead 数据库。如果运行 php artisan migrate --database=test ,它将迁移到测试数据库。
关于php - Laravel 5 php artisan migrate --数据库参数不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37833327/