相关疑难解决方法(0)

Sequelize不会创建外键作为约束

我们正在尝试使用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)

难道我做错了什么?

postgresql sequelize.js

2
推荐指数
1
解决办法
3237
查看次数

标签 统计

postgresql ×1

sequelize.js ×1