PHP工匠迁移不起作用

时间:2018-04-16 13:33:08

标签: php laravel laravel-5 artisan-migrate

这是我的配置详细信息 - 它是100%正确的

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=bglee
DB_USERNAME=root
DB_PASSWORD=

迁移文件

Schema::create('users', function (Blueprint $table) {
            $table->char("name" , 80);
            $table->char("username" , 50)->primary();
            $table->char("email" , 50)->unique();
            $table->char("password",50);
            $table->char("phone",25)->unique();
            $table->char("country",40)->nullable();
            $table->char("government",40)->nullable();
            $table->char("area",40)->nullable();
            $table->string("address")->nullable();
            $table->char("floor",20)->nullable();
            $table->char("apart",20)->nullable();
            $table->char("gender",10)->nullable();
            $table->integer("byear")->nullable();
            $table->integer("bmonth")->nullable();
            $table->integer("bday")->nullable();
            $table->char("aphone",25)->nullable();
            $table->integer("points")->default(0);
            $table->timestamps();
        });

PHP artisan migrate总是触发这些错误

  

PDOException::(“SQLSTATE [HY000] [1049]未知数据库'bglee'”)

我使用最后一个版本的laravel

数据库名称正确且存在

enter image description here

3 个答案:

答案 0 :(得分:0)

如果您使用vagrant而不是尝试此步骤

  • vagrant ssh
  • cd / var / www / yourproject
  • php artisan migrate

答案 1 :(得分:0)

检查数据库是否创建。

然后检查配置详细信息和.env,不留尾随空格。 应用程序/配置/ database.php中

最后清除缓存,配置和视图

答案 2 :(得分:0)

<强>解决

我无法解释导致此问题发生的逻辑原因

我通过MAMP使用PhpMyAdmin和从此命令生成的本地主机:php artisan serve - 我的项目文件夹在桌面上

现在我通过XAMPP使用PhpMyAdmin并将MySQL端口更改为3333,并将.env文件中的端口变量更改为3333,同时将项目文件夹移动到XAMPP htdocs文件夹..完成

抱歉 - 我无法理解为什么会出现这个问题