node-koa查询mysql 报错没有表,写入却正常,请大佬指点。。

新手上路,请多包涵

首先,我肯确定的是,数据库正常连接,有相应的数据表。而且写入正常。

mysql> select * from appoint where id=1;
idnamephoneweixinmessage

通过手动查询没有毛病。

以下是写入数据库的代码,前端也能正常调用,写入。

if (phone !== "" || weixin !== "") {
    database.query(`INSERT INTO appoint (name,weixin,phone,message) VALUES ('${name}','${weixin}','${phone}','${message}')`,
        (err, result) => {
            if (err) { console.log(err.message); }
        })
}

以下是读取代码,显示没有对应的数据表,我很无语。

database.query("SELECT * FROM appoint",(err,result) => {
    if(err) {reject(ctx.response.body = `出错了${err.message}`)}
    console.log(typeof result);
    resolve(ctx.response.body = result);
})
})
Error: non-error thrown: "出错了ER_NO_SUCH_TABLE: Table 'anxin.APPOINT' doesn't exist"
  at Object.onerror (/root/anxin/node_modules/koa/lib/context.js:119:31)
  at onerror (/root/anxin/node_modules/koa/lib/application.js:165:32)
  at <anonymous>
  at process._tickCallback (internal/process/next_tick.js:188:7)`
阅读 1.6k
1 个回答

1、有可能是MySQL设置了参数lower_case_table_names,这个值设置为大小写敏感
2、有可能是这个表和其所属的schema不匹配

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题