提示如下:does not have a primary key. You should either define a primary key for the corresponding table or override the primaryKey() method


我们需要去models进行设置:
/**
* 指定主键
* @return array|string[]
*/
public static function primaryKey()
{
return ['key'];
}
本文介绍了一种解决在没有定义主键的情况下遇到的错误的方法。通过在模型中定义 primaryKey 方法,可以为对应的表指定主键,从而避免 doesnothaveaprimarykey 错误。文章提供了具体的代码示例。
2724

被折叠的 条评论
为什么被折叠?



