“我的迁移文件在运行时引发错误”;“php artisan迁移”;

“我的迁移文件在运行时引发错误”;“php artisan迁移”;,php,laravel,laravel-6,php-7.2,Php,Laravel,Laravel 6,Php 7.2,我得到的错误如下 “Illumb\Database\QueryException:SQLSTATE[42S22]:找不到列:在where子句中1054未知列‘键’(SQL:select*fromadmin\u设置where键!=null限制1)” 由于app/Providers/AppServiceProvider.php中的函数 public function boot() { if (Schema::hasTable('admin_settings')) {

我得到的错误如下

“Illumb\Database\QueryException:SQLSTATE[42S22]:找不到列:在where子句中1054未知列‘键’(SQL:select*from
admin\u设置
where
!=null限制1)”

由于app/Providers/AppServiceProvider.php中的函数

 public function boot()
    {
        if (Schema::hasTable('admin_settings')) {
            $google_analytics_details = AdminSetting::where('key','!=','null')->first();

        }else {
            $google_analytics_details = '';
        }        
        View::share('google_analytics_details', $google_analytics_details);
    }

当我注释引导函数的代码时,它会成功迁移

我正在寻找这种观点分享的替代方案。 有人能帮我吗

我的迁移文件内容:

<?php

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

class UpdateAdminSettingsTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        //
         Schema::table('admin_settings', function (Blueprint $table) {
            $table->dropColumn('google_analytics_code');
        });

        Schema::table('admin_settings', function (Blueprint $table) {
            $table->longText('key')->nullable()->after('id');
            $table->longText('value')->nullable()->after('key');

        });

    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        //
         Schema::table('admin_settings', function (Blueprint $table) {

        });


    }
}

您可以使用

如果要将变量共享到一个视图(可以加载或扩展到其他视图,例如
layout.app
),可以指定视图名称,如下例所示

简单的例子:

View::composer('view-name', function ($view) {
             $view->with('key', 'value');
        });
或者,如果您在所有视图中都需要它,您可以使用
*
作为视图名称,如下所示

View::composer('*', function ($view) {
             $view->with('key', 'value');
        });
另一种解决问题的方法 您的迁移问题也可以在共享视图之前通过条件解决

 public function boot()
    {
        if ( !app()->runningInConsole() ){
             // your code here
        }
    }


是否在标题中包含“Use App/AdminSetting”?是否有键字段?表中是否有该列?你能发布你的迁移吗?也许用?你的桌子结构是什么?你检查过这个栏目的名称了吗?(Key vs Key等)那么您的表存在,但该列不存在?您可以使用
if(Schema::hascollan('admin_settings','key'){/}
检查该列是否存在