我的迁移文件在运行“php artisan migrate”时出现错误

我得到的错误是


“Illuminate\Database\QueryException:SQLSTATE[42S22]:未找到列:1054 ‘where 子句’中的未知列‘key’(SQL:从其中选择 *!=admin_settings空key限制 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) {


        });



    }

}


达令说
浏览 112回答 1
1回答

ABOUTYOU

如果您想将变量共享到一个视图(可以加载或扩展到其他视图,例如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        }    }
打开App,查看更多内容
随时随地看视频慕课网APP