【发布时间】:2020-03-20 03:06:03
【问题描述】:
我在 Laravel 6.5.1 中有一个模型用户。
class User extends Authenticatable
{
use Notifiable;
public $table = 'usuario';
public $primaryKey = 'cif_usu';
public $incrementing = false;
public $timestamp = false;
//...
}
但是,当我尝试选择用户时,我收到以下错误:
SQLSTATE[42703]:未定义列:7 错误:列“id”不存在 LINE 1: select * from "usuario" where "id" = $1 limit 1 ^ (SQL: select * 来自 "usuario" 其中 "id" = 24 限制 1)
如何重命名 id 列?
编辑:
我变了:
public $primaryKey = 'cif_usu';
到:
protected $primaryKey = 'cif_usu';
结果是一样的
【问题讨论】:
-
那么,在您的“usuario”表中,主键是“cif_usu”吗?查看文档上的Eloquent Model Conventions