最近在用MySQL结合typeorm开发,其中出现一个错误,如下:
[Nest] 6424 - 2018-12-13 11:45:30 [ExceptionsHandler] ER_BAD_FIELD_ERROR: Unknown column 's.userId' in 'where clause' +38211ms
代码如下:
await this.em.createQueryBuilder()
.update(SignDao)
.set({number: signDao.number, lastModifyTime: signDao.lastModifyTime, signCount: signDao.signCount})
.where('s.userId = :userId', {userId})
.execute();
查typeorm demo文档发现,更新操作的写法是:
import {getConnection} from "typeorm";
await getConnection()
.createQueryBuilder()
.update(User)
.set({ firstName: "Timber", lastName: "Saw" })
.where("id = :id", { id: 1 })
.execute();
对比发现是以为 s 根本就不存在,没定义,所以没找到,去掉s 问题解决

网友评论