gpt4 book ai didi

javascript - 带有 Sequelize 的 Node.js 上的 SQL Server 2008

转载 作者:行者123 更新时间:2023-11-30 16:43:24 25 4
gpt4 key购买 nike

我是新来的!

我正在尝试使用 sequelize 在 MS SQL Server2008 上进行查询,但出现此错误:

Unhandled rejection SequelizeDatabaseError: Invalid column name 'id'. at Query.formatError (C:\xampp\htdocs\Lavori\Bit_Sense\API_BS\node_modules\s equelize\lib\dialects\mssql\query.js:217:10) at Request.userCallback (C:\xampp\htdocs\Lavori\Bit_Sense\API_BS\node_module s\sequelize\lib\dialects\mssql\query.js:66:25) at Request.callback (C:\xampp\htdocs\Lavori\Bit_Sense\API_BS\node_modules\te dious\lib\request.js:30:27) at Connection.STATE.SENT_CLIENT_REQUEST.events.message (C:\xampp\htdocs\Lavo ri\Bit_Sense\API_BS\node_modules\tedious\lib\connection.js:283:29) at Connection.dispatchEvent (C:\xampp\htdocs\Lavori\Bit_Sense\API_BS\node_mo dules\tedious\lib\connection.js:752:59) at MessageIO. (C:\xampp\htdocs\Lavori\Bit_Sense\API_BS\node_modul es\tedious\lib\connection.js:685:22) at MessageIO.emit (events.js:104:17) at MessageIO.eventData (C:\xampp\htdocs\Lavori\Bit_Sense\API_BS\node_modules \tedious\lib\message-io.js:58:21) at Socket. (C:\xampp\htdocs\Lavori\Bit_Sense\API_BS\node_modules\ tedious\lib\message-io.js:3:59) at Socket.emit (events.js:107:17) at readableAddChunk (_stream_readable.js:163:16) at Socket.Readable.push (_stream_readable.js:126:10) at TCP.onread (net.js:538:20)

我已经安装了这个模块:- Sequelize ;- 乏味;

我的连接没有问题,只有这个查询:

db.KEY_ARTI.findAll({
where:{
CACODICE: cacodice
}
}).then(function(data) {
res.send(data);
});

我能做什么?我没有任何名为 id 的列

这是我的表格:

var Sequelize = require('sequelize');
var settings = global.settings.databases.DATABASE;
var errors = global.errors;
var utilities = global.utilities;

var sequelize = new Sequelize(settings.schema, settings.username, settings.password, {
dialect: settings.dialect,
host: settings.host,
port: settings.port, /* BISOGNA USARE LA DYNAMIC PORT */
logging: function (str) {
if(settings.log)
console.log("querylog: "+str.replace("Executing (default):", "") );
},
});

sequelize.authenticate().then(function(err) {
if (!!err) {
console.log('Database '+settings.schema+' Connection Error:', err)
}
else {
console.log('Database '+settings.schema+' Connected')
}
});

exports.sequelize = sequelize;

/*
* KEY_ARTI
*/
exports.KEY_ARTI = sequelize.define('KEY_ARTI', {
CACODICE: Sequelize.CHAR(20),
CADESART: Sequelize.CHAR(40),
}

最佳答案

默认情况下,sequelize 将添加一个名为 id 的主键,如果您自己不做任何事情。

sequelize.define('model', {}); // Adds an id key

sequelize.define('model', {
name: {
primaryKey: true
type: Sequelize.STRING
}
}); // Doesn't add an id, because you already marked another column as primary key

也可以有一个没有主键的模型,但我不推荐这样做

关于javascript - 带有 Sequelize 的 Node.js 上的 SQL Server 2008,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31593374/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com