【发布时间】:2014-12-12 20:12:24
【问题描述】:
我们正在尝试使用 Sequelize 在 PostgreSQL 中自动创建表。不幸的是,它不会将外键创建为约束。这是我的一个模型的示例:
module.exports = function(schema, DataTypes) {
var definition = {
id: {
type: DataTypes.INTEGER,
primaryKey: true,
autoIncrement: true
},
deal_id: {
type: DataTypes.INTEGER
},
image: DataTypes.STRING,
};
var image = schema.define('Image', definition, {
tableName: 'images', // this will define the table's name
timestamps: false, // this will deactivate the timestamp columns
syncOnAssociation: true,
classMethods: {
getDefinition: function() {
return definition;
},
associate: function(_models) {
image.belongsTo(_models.Product, {
foreignKey: 'deal_id'
});
}
}
});
return image;
};
我是不是做错了什么?
【问题讨论】: