【发布时间】:2020-05-19 05:29:08
【问题描述】:
我得到的错误是
“Illuminate\Database\QueryException : SQLSTATE[42S22]: 找不到列: 1054 'where 子句'中的未知列 'key' (SQL: select * from
admin_settingswherekey!= null limit 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) {
});
}
}
【问题讨论】:
-
您是否在标题中加入了“使用 App/AdminSetting”?
-
有关键字段吗?
-
表格中有那一列吗?你能发布你的迁移吗?也许使用View Composers?
-
你的表结构是什么?您是否拼写检查了列的名称? (键与键等)
-
所以您的表存在但该列不存在?您可以使用
if (Schema::hasColumn('admin_settings', 'key')) { // }检查该列是否存在
标签: php laravel laravel-6 php-7.2