分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > IT知识

thinkjs中修改默认主键

发布时间:2023-09-06 01:55责任编辑:彭小芳关键词:js

报错信息:

{ Error: ER_BAD_FIELD_ERROR: Unknown column ‘a_role.id‘ in ‘field list‘

还原场景:

a_role这张表没有自增的id,主键为roleid.如果在thinkjs的控制器中写查询这张表的数据sql时,就出现了这样错误。

解决方法:

修改后的代码:

 1 async listAction() { 2 ????????let getData = this.get(); 3 ????????let role = this.model(‘a_role‘); 4 ??????? role._pk = ‘roleid‘; 5 ????????let whereobj = {};//状态:1:正常 ;-1:禁用 6 ????????if (getData.roleid) {//角色ID 7 ????????????whereobj[‘roleid‘] = ?getData.roleid; 8 ????????} 9 ????????if (getData.rolename) {//角色名称10 ????????????whereobj[‘rolename‘] = [‘like‘, ‘%‘ + getData.rolename + ‘%‘];11 ????????}12 ????????if (getData.state && getData.state != -99) {13 ????????????whereobj.state = getData.state;14 ????????}15 ????????let result = await role.field(‘roleid,rolename,state‘)16 ????????????.where(whereobj)17 ????????????.order("roleid asc")18 ????????????.page(getData.pageNumber, getData.pageSize)19 ????????????.countSelect();20 ????????return this.json({ total: result.count, rows: result.data });21 ????}

thinkjs中修改默认主键

原文地址:https://www.cnblogs.com/zhengyeye/p/9071449.html

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved