【问题标题】:php artisan migrate is not doing anythingphp artisan migrate 没有做任何事情
【发布时间】:2019-02-09 08:07:20
【问题描述】:

我已经在我的 Macbook Pro(运行 High Sierra (10.13.6))上使用 Homebrew 安装了 Laravel 5 和 Valet (v2.0.12)。我已经下载了一个干净的 Laravel 项目 (laravel new blog)。

当我尝试迁移(坐在项目文件夹中,然后使用php artisan migrate)时,什么也没有发生。终端只是坐在那里无所事事。命令正在执行,但什么也没有。没有错误,没有成功,什么都没有。即使添加 -v 也没有任何效果。

我可以通过命令行进入服务器。我在.env 文件中输入了正确的凭据。我什至可以运行其他php artisan 命令,但所有migrate 命令都不执行任何操作。

我的迁移文件是:

2018_09_04_100609_create_users_table.php

<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateUsersTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('users', function (Blueprint $table) {
            $table->increments('id');
            $table->string('name');
            $table->string('email')->unique();
            $table->string('password');
            $table->rememberToken();
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('users');
    }
}

2018_09_04_100659_create_password-resets_table.php

<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreatePasswordResetsTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('password_resets', function (Blueprint $table) {
            $table->string('email')->index();
            $table->string('token');
            $table->timestamp('created_at')->nullable();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('password_resets');
    }
}

更新:

使用以下方法检查数据库连接:

try {
    DB::connection();
    die("success!");
} catch (\Exception $e) {
    die("Could not connect to the database.  Please check your configuration. error:" . $e );
}

我得到了“成功!”。

但后来我将DB::connection() 更改为DB::connection()-&gt;getPdo() 它不再执行任何操作。还是不相关?

【问题讨论】:

  • 愿意分享您的迁移文件吗?没有它,我们只能猜测。
  • 你在迁移文件夹中建表了吗?
  • 我已将代码添加到我的原始帖子中。
  • 试试 php artisan migrate --force
  • @Mtxz stackoverflow.com/questions/33432752/…检查这个问题,你也可以分享你的env文件(db部分)

标签: php laravel laravel-artisan artisan-migrate


【解决方案1】:

我把它修好了。之后我会添加很多感叹号,但我不喜欢这样。为什么?

因为问题在于我使用的是 MySQL,而我应该一直使用 MariaDB。该指南在任何地方都没有提到这一点,所以我只是假设 MySQL 就足够了。显然不是。如果错误显示类似的东西会很好......

【讨论】:

  • 你是怎么修好的?
  • @Raccoon 如果我没记错的话,我从 MySQL 切换到 MariaDB,但不幸的是我不记得具体细节了。
【解决方案2】:

我遇到了类似的问题,其中没有任何迁移选项或迁移本身起作用,并且我没有收到任何错误,该命令似乎挂起。在遇到此页面并经过许多其他尝试后,我从 MySQL 切换到 MariaDB。这终于奏效了。

我就是这样做的。在这篇文章之后:-How To Install MariaDB on Ubuntu 20.04(我将它安装到 digitalocean 上的一个液滴上,但我相信这个概念会对任何人都有帮助。

安装 MariaDB:

sudo apt update
sudo apt install mariadb-server
sudo mysql_secure_installation

打开 MariaDB 并创建管理员用户:

sudo mariadb
GRANT ALL ON *.* TO 'admin'@'localhost' IDENTIFIED BY 'password' WITH GRANT OPTION;
FLUSH PRIVILEGES;
exit;

测试以确保数据库按需要运行:

sudo systemctl status mariadb

如果没有运行:

sudo systemctl start mariadb

如需完整说明,请访问我分享的链接

此外,如果您已经安装了 MySQL,则必须将其删除,否则将导致 MariaDB 在重新启动时失败。后来我遇到了这个问题,当我尝试启动它时,MariaDB 一直挂起,并且在浏览器上出现 MYSQL 2002 错误。方法如下-

sudo systemctl stop mariadb
echo "/usr/sbin/mysqld { }" | sudo tee /etc/apparmor.d/usr.sbin.mysqld
sudo apparmor_parser -v -R /etc/apparmor.d/usr.sbin.mysqld

运行这些命令应该会显示

Removal succeeded for "/usr/sbin/mysqld".

然后,运行这个

sudo ln -s /etc/apparmor.d/usr.sbin.mysqld /etc/apparmor.d/disable/usr.sbin.mysqld

最后重启mariadb

sudo systemctl start mariadb

现在一切都应该运行良好,即使在重新启动后也会保留。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-09-07
    • 2016-10-02
    • 2013-09-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多