繁体   English   中英

QueryException SQLSTATE [42S22]:找不到列:1054“ where子句”中的未知列“ customers.id”

[英]QueryException SQLSTATE[42S22]: Column not found: 1054 Unknown column 'customers.id' in 'where clause'

我想在laravel系统中编辑数据,该系统具有一个customer_id作为增量键。 但是错误说

Illuminate \\ Database \\ QueryException(42S22)SQLSTATE [42S22]:找不到列:1054“ where子句”中的未知列“ customers.id”(SQL:从* where customers选择* customers = id 4限制1)

以前的例外

SQLSTATE [42S22]:找不到列:1054“ where子句”中的未知列“ customers.id”(42S22)

我不明白为什么。

我试图在模型中添加受保护的主键customer_id。 但是结果和以前一样。

这是我的控制器

    {
        $customer = \App\Customer_Model::find($customer_id);
        $customer->delete();
        return redirect('/customers')->with('sukses', 'Users has been deleted!');
    }

这是我的模特


namespace App;

use Illuminate\Database\Eloquent\Model;

class Customer_Model extends Model
{
    protected $table = 'customers';
    protected $primarykey = 'customer_id';
    protected $fillable = ['customer_id', 'customer_code', 'customer_name', 'email', 'phone', 'contact_person', 'address', 'user_id', 'created_by', 'updated_by', 'void'];
}```

This is my view
```<tbody>
                      @foreach($data_customer as $cust)
                        <tr>
                        <td>{{$cust->customer_code}}</td>
                        <td>{{$cust->customer_name}}</td>
                        <td>{{$cust->email}}</td>
                        <td>{{$cust->phone}}</td>
                        <td>{{$cust->contact_person}}</td>
                        <td>{{$cust->address}}</td>
                        <td><a href="/customers/{{$cust->customer_id}}/edit" class="btn btn-warning"><span class="icon-settings icons icon"></span></a><a href="/customers/{{$cust->customer_id}}/delete" class="btn btn-danger"><span class="icon-trash icons icon"></span></a></td>
                        </tr>
                        @endforeach
                      </tbody>```

$primaryKey更改$primarykey $primaryKey 该变量区分大小写,Laravel正在寻找$primaryKey (大写的“ K”)

暂无
暂无

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM