![](/img/trans.png)
[英]How can I give primary key and foreign key relationship in Sequelize.js + Postgres.js
[英]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.