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

标签 php database laravel console migration

我想使用控制台命令迁移数据库

当我尝试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/

相关文章:

php - Thinkphp中如何在数据库中存储多行

mongodb - 没有仲裁器的两个节点 MongoDB 副本集

php - PHP 中的 Time() 函数

php - 使用 CodeIgniter 和 jQuery(AJAX) 的一页网站

php - jQuery 发布和获取表单数据

html - 使用 VueJs 添加动态输入字段

laravel - 如何修复“Laravel 中不存在该文件...”?

php - 拉维尔 5 : Restrict access to controllers by User group

c# - 我们可以像在 c# 中的数据库中那样以排序方式将数据填充到文本框中吗?

laravel - 将 StdClass 数据移植到模型