2013-04-11 46 views
0
$account = Account::where('account_id', '=', $account_id)->first(); 
$account->username = 'New_Username'; 
$account->password = 'Password'; 
$account->save(); 

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

为什么会发生这种情况?Laravel3:在UPDATE语句中的口才/流利失败

+0

您的表是否有ID列? – 2013-04-11 00:29:11

+0

不是。 account_id作为自动增量。 – Aristona 2013-04-11 00:36:54

回答

2

更新Eloquent模型时,它将使用模型的主键。默认的主键是id,您可以通过添加在你的类中的下列更改此:

public static $key = 'account_id'; 

被警告,有在Laravel id一些硬编码引用,所以最好的建议还是使用id作为设计用于Eloquent的数据库时的主要关键。

参考:laravel/database/eloquent/model.php

+0

我在我自己的数据库中使用id作为主键,但它是我正在处理的另一个数据库,它包含它。我现在不想清理引用,所以我会坚持使用您的解决方案。 – Aristona 2013-04-11 00:39:59