我的迁移文件在 运行 "php artisan migrate" 时引发错误
My migration file raising an error while running "php artisan migrate"
我得到的错误是
"Illuminate\Database\QueryException : SQLSTATE[42S22]: Column not found: 1054 Unknown column 'key' in 'where clause' (SQL: select * from admin_settings
where key
!= 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) {
});
}
}
你可以使用view composers doc
如果您想将变量共享到一个视图(可以加载或扩展到其他视图,例如 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
}
}
我得到的错误是
"Illuminate\Database\QueryException : SQLSTATE[42S22]: Column not found: 1054 Unknown column 'key' in 'where clause' (SQL: select * from
admin_settings
wherekey
!= 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) {
});
}
}
你可以使用view composers doc
如果您想将变量共享到一个视图(可以加载或扩展到其他视图,例如 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
}
}