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

时间:2014-06-26 01:35:24

标签: javascript mysql sql node.js sequelize.js

我有一个名为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表?如果没有,还有另一种方式吗?

1 个答案:

答案 0 :(得分:6)

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)
})