Laravel php artisan迁移空数据库上的错误

Laravel php artisan迁移空数据库上的错误,php,laravel,laravel-5,migration,laravel-artisan,Php,Laravel,Laravel 5,Migration,Laravel Artisan,奇怪的事情正在发生。一直在尝试使用php artisan migrate运行迁移,但出现以下关于缺少表的错误(该表应该由迁移创建和填充) 拉威尔版本:5.5* PHP版本:7.1 背景故事: 我决定安装一个新的本地数据库,而不是一直依赖远程数据库。然后我发现artisan不再工作了 尝试: 每一个artisan命令我都可以使用,但是没有一个有效,因为即使是php artisan--help也会抛出上面的错误 我还尝试克隆repo作为一个新的开始,然后检查我正在处理的分支,并运行php artis

奇怪的事情正在发生。一直在尝试使用
php artisan migrate
运行迁移,但出现以下关于缺少表的错误(该表应该由迁移创建和填充)

拉威尔版本:5.5*

PHP版本:7.1

背景故事:

我决定安装一个新的本地数据库,而不是一直依赖远程数据库。然后我发现artisan不再工作了

尝试:

每一个artisan命令我都可以使用,但是没有一个有效,因为即使是
php artisan--help
也会抛出上面的错误

我还尝试克隆repo作为一个新的开始,然后检查我正在处理的分支,并运行
php artisan migrate
,但出现了相同的错误

迁移:

我不能全部发布,但有一个迁移构建了丢失的表:

<?php

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

class CreatePortalLinks extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('portal_viewer_user', function (Blueprint $table) {
            $table->integer('viewer_user_id');
            $table->integer('portal_id');
        });

        Schema::create('admin_user_portal', function (Blueprint $table) {
            $table->integer('admin_user_id');
            $table->integer('portal_id');
        });

        Schema::create('portals', function (Blueprint $table) {
            $table->increments('id');
            $table->string('identifier');
            $table->timestamps();
        });
    }

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

您正在尝试刷新

您应该尝试php artisan迁移:fresh

“向下”命令将不起作用,因为没有要删除的内容


当你运行refresh命令时,laravel将首先尝试使用down函数回滚所有内容。然后它将重建所有内容。在服务器上,你从来没有遇到过问题,因为那些表都在那里。但在这里,在一个新的安装,整个事情不能回滚。没有可回滚的内容。

您正在尝试刷新

您应该尝试php artisan迁移:fresh

“向下”命令将不起作用,因为没有要删除的内容

当你运行refresh命令时,laravel将首先尝试使用down函数回滚所有内容。然后它将重建所有内容。在服务器上,你从来没有遇到过问题,因为那些表都在那里。但在这里,在一个新的安装,整个事情不能回滚。没有要回滚的内容。

错误原因:

错误是由在其构造函数中包含数据库查询的Laravel服务提供商引起的

事实证明——我不知道这一点——Laravel服务提供者在运行artisan时得到实例化

解决方案:

一旦我在我的服务提供商中进行了一些验证以阻止artisan命令上发生查询,运行
php artisan migrate:install
php artisan migrate:fresh
,以及
php artisan migrate--seed
,由数据库填充所有必要的表和记录。

错误原因:

错误是由在其构造函数中包含数据库查询的Laravel服务提供商引起的

事实证明——我不知道这一点——Laravel服务提供者在运行artisan时得到实例化

解决方案:



一旦我在服务提供商中进行了一些验证,以阻止artisan命令上发生查询,运行
php artisan migrate:install
php artisan migrate:fresh
,php artisan migrate--seed
由数据库填充,包含所有必要的表和记录。

也许您有一个迁移,它试图修改一个尚不存在的表。在没有看到迁移的情况下很难进行诊断……您可以发布这些吗?您是否尝试过“php artisan迁移:刷新”?显示您的迁移。当你开始处理本地数据库时,你确实迁移了远程数据库吗?@ka_lin Yup,它给了我同样的错误:(@aynber)因此,我的一个服务提供商在其构造函数中查询数据库,从而导致
php artisan
在任何迁移可以运行之前完全失败。运行命令
php artisan migrate:install
,然后运行
php artisan migrate:fresh
,它用所有表填充了我的数据库!也许你我有一个迁移,它试图修改一个尚不存在的表。如果没有看到迁移,很难进行诊断…你能发布这些迁移吗?你是否尝试过“php artisan migrate:refresh”?显示你的迁移。当你开始处理本地数据库时,你确实迁移了远程数据库吗?@ka_lin Yup,它给了我同样的错误:(@aynber,原来我的一个服务提供商在其构造函数中查询数据库,从而导致
php artisan
在任何迁移可以运行之前完全失败。运行命令
php artisan migrate:install
,然后运行
php artisan migrate:fresh
,它用所有表填充我的数据库!不起作用。I运行与
php artisan
有关的任何操作时都会出现此错误,不幸的是:(错误显示为
'select*from
..”`Array,这似乎表明某个地方的某些迁移假设某个表已经存在。有关迁移的更多详细信息?我想到的另一件事是一次运行一个表的迁移。这样,您就可以准确地确定问题所在。例如,编辑代码到
…public function up(){Schema::create('portal_viewer_user',function(Blueprint$table){$table->integer('viewer_user_id');$table->integer('portal_id');)}
Hm…似乎不起作用。但是,我注意到,当我运行
php artisan
时,我的PortalService正在实例化……我猜这不应该发生?因此我的PortalService在其构造函数中有一个db查询,每次运行
php artisan
命令时都会失败。我添加了一些验证来防止查询失败发生在CLI中,修复了我文章中的错误!然后我运行了
php artisan migrate:install
php artisan migrate:fresh
,这两个程序在我的数据库中创建了所有表。不起作用。在运行与
php artisan
有关的任何操作时,我一直遇到此错误,不幸的是:(错误显示为
'select*from
..`Array,这似乎表明某个地方的某些迁移假设某个表已经存在。有关迁移的更多详细信息?我想到的另一件事是运行mig
<?php

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

class CreatePortalLinks extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('portal_viewer_user', function (Blueprint $table) {
            $table->integer('viewer_user_id');
            $table->integer('portal_id');
        });

        Schema::create('admin_user_portal', function (Blueprint $table) {
            $table->integer('admin_user_id');
            $table->integer('portal_id');
        });

        Schema::create('portals', function (Blueprint $table) {
            $table->increments('id');
            $table->string('identifier');
            $table->timestamps();
        });
    }

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