繁体   English   中英

Node.js的Sequelize.js可以定义一个主键未命名为“id”的表吗?

[英]Can Sequelize.js for Node.js define a table where the Primary Key is not named 'id'?

我有一个名为things的简单MySQL表。 我的things表有三列:

Column Name  Data Type
===========  ============
thing_id     INT           // The auto increment Primary Key
thing_name   VARCHAR(255)
thing_size   INT

据我所知Sequelize.js期望/要求主键被命名为'id'。

有没有办法使用标准的sequelize.define()调用来定义我的things表? 如果没有,还有另一种方式吗?

尝试

var Test = sequelize.define( 'things', {
    thing_id   : {type: Sequelize.INTEGER(11), primaryKey: true, autoIncrement: true},
    thing_name          : {type: Sequelize.STRING(255)},
    thing_size      : {type: Sequelize.INTEGER}
},{
});

Test.sync()
.success(function(){
    console.log('table created');
})
.error(function(error){
    console.log('failed', error)
})

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM