Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
$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'
为什么会这样?
当您更新 Eloquent 模型时,它将使用模型的主键。默认主键是id,您可以通过在类中添加以下内容来更改它:
id
public static $key = 'account_id';
请注意,在 Laravel 中有一些硬编码的引用id,因此最好的建议仍然是在为 Eloquentid设计数据库时将其用作主键。
参考:laravel/database/eloquent/model.php