我有一个名为Product的模型,它有两个字段id和name。我有脚印。
'use strict'
const Model = require('trails/model')
/**
* @module Product
* @description TODO document Model
*/
module.exports = class Productextends Model {
static config (app, Sequelize) {
return {
store: 'db',
options: {
schema: 'dbo',
tableName: 'dimProduct',
timestamps: false,
classMethods: {
//If you need associations, put them here
associate: (models) => {
}
}
}
}
}
static schema (app, Sequelize) {
return {
id: {
type: Sequelize.STRING,
allowNull: false,
primaryKey: true,
field: 'ProductCode'
},
name: {
type: Sequelize.STRING,
field: 'ProductName'
}
}
}
}当我使用postman并获得请求localhost:3000/product?id=XX2525时,在记录器中生成的sql是
SELECT [Product].[ProductCode] AS [id], [Product].[ProductName] AS [name] FROM [dbo].[dimProduct] AS [Product] WHERE [Product].[ProductCode] = N'XX2525';如果我对以数字localhost:3000/product?id=10XX2525开头的id执行相同的查询,则生成的sql为
SELECT [Product].[ProductCode] AS [id], [Product].[ProductName] AS [name] FROM [dbo].[dimProduct] AS [Product] WHERE [Product].[ProductCode] = 10;我不确定这是跟踪问题还是后缀问题,但是如果我在模型中将我的字段定义为字符串,我希望查询会搜索为tring,而不会应用任何转换。错误看起来是(001CAR是我的数据库中的第一个id ):
{
"name": "SequelizeDatabaseError",
"message": "Conversion failed when converting the varchar value '1CAR' to data type int.",
"parent": {
"message": "Conversion failed when converting the varchar value '1CAR' to data type int.",
"code": "EREQUEST",
"number": 245,
"state": 1,
"class": 16,
"serverName": "db",
"procName": "",
"lineNumber": 1,
"sql": "SELECT [Product].[ProductCode] AS [id], [Product].[ProductName] AS [name] FROM [dbo].[dimProduct] AS [Product] WHERE [Product].[ProductCode] = 10;"
},
"original": {
"message": "Conversion failed when converting the varchar value '1CAR' to data type int.",
"code": "EREQUEST",
"number": 245,
"state": 1,
"class": 16,
"serverName": "db",
"procName": "",
"lineNumber": 1,
"sql": "SELECT [Product].[ProductCode] AS [id], [Product].[ProductName] AS [name] FROM [dbo].[dimProduct] AS [Product] WHERE [Product].[ProductCode] = 10;"
},
"sql": "SELECT [Product].[ProductCode] AS [id], [Product].[ProductName] AS [name] FROM [dbo].[dimProduct] AS [Product] WHERE [Product].[ProductCode] = 10;",
"isBoom": true,
"isServer": true,
"data": null,
"output": {
"statusCode": 500,
"payload": {
"statusCode": 500,
"error": "Internal Server Error",
"message": "An internal server error occurred"
},
"headers": {}
}
}我的package.json依赖项是,我正在运行节点v6.11.5
"dependencies": {
"ejs": "^2.5.7",
"express": "^4.16.2",
"tedious": "^2.0.0",
"trailpack-express": "^2.0.3",
"trailpack-footprints": "^2.0.0",
"trailpack-repl": "v2-latest",
"trailpack-router": "v2-latest",
"trailpack-sequelize": "^2.0.0",
"trails": "v2-latest"
}发布于 2017-10-31 07:28:23
您会遇到一个已经由这个PR https://github.com/trailsjs/trailpack/pull/44修复的错误,但是修复显然没有部署在npm上。
trailpack-express v2.0.6现在有了这个修复程序,更新它,您就不会再有问题了
https://stackoverflow.com/questions/47025208
复制相似问题