简体   繁体   English

错误:SQLSTATE[42S22]:未找到列:1054 'where 子句'中的未知列 '0'

[英]ERROR: SQLSTATE[42S22]: Column not found: 1054 Unknown column '0' in 'where clause'

I have a Laravel-Page and since i want to add a "soft delete" with the active field in the DB i get that error:我有一个 Laravel-Page,因为我想在数据库中的活动字段中添加一个“软删除”,所以我收到了这个错误:

emails.ERROR: SQLSTATE[42S22]: Column not found: 1054 Unknown column '0' in 'where clause' (SQL: select * from categories where ( 0 = active and 1 = is active) order by name asc) emails.ERROR: SQLSTATE[42S22]: Column not found: 1054 Unknown column '0' in 'where clause' (SQL: select * from categories where ( 0 = active and 1 = is active) order by name asc)

-> which causes a error 500 obviously -> 显然会导致错误 500

and I have no plan how to fix this cause it looks like everything is fine.我没有计划如何解决这个问题,因为看起来一切都很好。

DB-Layout数据库布局

 Schema::create('categories', function (Blueprint $table) {
        $table->id();
        $table->string('name');
        $table->string('image')->nullable();
        $table->string('description')->nullable();
        $table->unsignedBigInteger('userID')->nullable();
        $table->string('active', 20)->default('is active');
        $table->timestamps();
    });

Model:模型:

protected $table = 'categories';

protected $fillable = ['id', 'name', 'image', 'description', 'userID', 'active', 'created_at', 'updated_at'];

Usage(as sample for all other):用法(作为所有其他示例):

$categories = DB::table('categories')
            ->where(['active', 'is active'])
            ->orderBy('name', 'asc')
            ->get();

or something like this:或类似的东西:

->where(['categoryID', $category->id], ['active', 'is active'])

This code is causing error.此代码导致错误。

$categories = DB::table('categories')
        ->where(['active', 'is active'])
        ->orderBy('name', 'asc')
        ->get();

Eloquent is expecting your where array to be in key and value pair.机锋期待您的其中阵列是在keyvalue对。 As you have not given it, it is using index as column name.由于您没有给出它,它使用index作为列名。

You should place it like this:你应该像这样放置它:

$categories = DB::table('categories')
        ->where('active', 'is active') //will also work ->where('active', '=', 'is active')
        ->orderBy('name', 'asc')
        ->get();

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 错误:SQLSTATE [42S22]:找不到列:1054“ where子句”中的未知列“ rowid” - Error: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'rowid' in 'where clause' 错误:SQLSTATE [42S22]:找不到列:1054 where子句中的未知列 - Error: SQLSTATE[42S22]: Column not found: 1054 Unknown column in where clause SQLSTATE [42S22]:找不到列:1054 'where 子句'中的未知列'Users.email' - SQLSTATE[42S22]: Column not found: 1054 Unknown column 'Users.email' in 'where clause' SQLSTATE [42S22]:找不到列:1054 'where 子句'中的未知列'名称' - SQLSTATE[42S22]: Column not found: 1054 Unknown column ' name' in 'where clause' SQLSTATE [42S22]:找不到列:1054 'where 子句'中的未知列'fighter.id_fighter' - SQLSTATE[42S22]: Column not found: 1054 Unknown column 'fighter.id_fighter' in 'where clause' SQLSTATE [42S22]:找不到列:1054 Yii 1.1中“ where子句”中的未知列“ registration” - SQLSTATE[42S22]: Column not found: 1054 Unknown column 'registration' in 'where clause' in Yii 1.1 SQLSTATE [42S22]:找不到列:1054“ where子句”中的未知列“ answers.question_id” - SQLSTATE[42S22]: Column not found: 1054 Unknown column 'answers.question_id' in 'where clause' SQLSTATE [42S22]:找不到列:1054“ where子句”中的未知列“ 0” - SQLSTATE[42S22]: Column not found: 1054 Unknown column '0' in 'where clause' SQLSTATE [42S22]:找不到列:1054“ where子句” Id中的未知列“ id”为空 - SQLSTATE[42S22]: Column not found: 1054 Unknown column 'id' in 'where clause' Id is null SQLSTATE[42S22]:未找到列:1054 'where 子句'中的未知列'用户名' - SQLSTATE[42S22]: Column not found: 1054 Unknown column 'username' in 'where clause'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM