mysql - Feathers - PATCH 时 where 子句中的未知列
问题描述
我正在为 mysql 数据库使用 Sequelize。
当我使用Find
Postman 的函数时,它返回:
{
"total": 1,
"limit": 10,
"skip": 0,
"data": [
{
"id": "1",
"latestNewsId": "f8b53a32-b729-41f8-9888-df2b71e91177"
}
]
}
然后我尝试使用, by修改latestNewsId
Postman 中的.Patch
id
PATCH localhost:3030/latest_news_featured/1
Body:
{
"latestNewsId": "f8b53a32-b729-41f8-9888-df2b71e12345"
}
这是发生的错误:
{
"name": "GeneralError",
"message": "Unknown column 'latest_news_featured.undefined' in 'where clause'",
"code": 500,
"className": "general-error",
"errors": {}
}
我不知道为什么会发生这种情况,因为我检查并确认id
并存latestNewsId
在于数据库中。
latest_news_featured.models.js
const Sequelize = require('sequelize');
const DataTypes = Sequelize.DataTypes;
module.exports = function (app) {
const sequelizeClient = app.get('sequelizeClient');
const latestNewsFeatured = sequelizeClient.define('latest_news_featured', {
id: {
type: DataTypes.STRING,
allowNull: false,
defaultValue: 1,
primaryKey: true
},
latestNewsId: {
type: DataTypes.UUID,
defaultValue: DataTypes.UUIDV4,
allowNull: false,
}
}, {
hooks: {
beforeCount(options) {
options.raw = true;
}
}
});
latestNewsFeatured.associate = function (models) { };
return latestNewsFeatured;
};
解决方案
在 中latest-news-featured.class
,当我发表评论时this.options = options || {};
,它会立即生效。
我不确定原因,所以我把它留在这里,希望它可以帮助其他有同样问题的人。
最新新闻-featured.class.js
const { Service } = require('feathers-sequelize');
exports.LatestNewsFeatured = class LatestNewsFeatured extends Service {
constructor (options,app) {
super(options, app);
this.app = app;
//this.options = options || {}; //Comment this line to make it works
}
...
...
};
推荐阅读
- python - 无法转换 numpy.object_ 类型的 np.ndarray
- python - 如何解决错误 TypeError: unsupported operand type(s) for /: 'Dimension' and 'float'
- c# - 进行一些图形调用后返回成功/错误响应
- javascript - 未调用模拟 res.status 上的快速控制器 getAllUsers 函数的开玩笑单元测试失败?
- jquery - Google Places api 按类型获取地址组件
- azure - Azure 定价 REST API 中的字段是什么意思?
- c# - textBox3 特定密钥以创建帐户
- c - 具有动态内存的 C 反向字符串
- excel - VLOOKUP 准确值和最接近的日期
- next.js - 无法设置 Apollo 客户端来处理在 NextJS 中设置授权令牌