我们正在尝试使用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;
};
Run Code Online (Sandbox Code Playgroud)
难道我做错了什么?