簡體   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