场景:修改数据时,唯一验证name字段出错,提示已存在。
排查:
1.传入的参数是否包含主键,因为 D('模型名')->create() 会自动判断是否是新增或者修改,根据传入的参数判断是否包含主键,如果包含主键则认为修改。
2.修改请求是否是post类型,因为D('模型名')->create() 自动检查post参数,如果不是post,请传入 D('模型名')->create($data). $data是你包含主键[id]和要修改的数据内容
3.如果主键[id]是通过url请求过来的[get],那么如果使用官方的 getData() 方法获取数据则有可能获取不到主键,建议直接接收post,主键再添加进入 $post['id'] = I('get.id')
4.检查自己设定验证时间是否正确,1 新增 2 修改 3 全部验证,[这里一定是填写3],因为如果是修改,tp3不会验证本条数据,只是判断其他数据行是否存在相同数据
5.是否在模型内设置 protected $insertFields 或 protected $updateFields , 如果包含主键id或其他需要的字段名,自动验证过后则会踢出不包含给定字段的其他数据
6.检查自己代码,变量等等是否编写正确,请求url是否编写正确
总结:
细心,多看文档,多百度.