Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/429.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/41.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 正在Console.log和api响应中获取未定义的外键_Javascript_Node.js_Postgresql_Foreign Keys_Sequelize.js - Fatal编程技术网

Javascript 正在Console.log和api响应中获取未定义的外键

Javascript 正在Console.log和api响应中获取未定义的外键,javascript,node.js,postgresql,foreign-keys,sequelize.js,Javascript,Node.js,Postgresql,Foreign Keys,Sequelize.js,我有一个表report\u data,它属于daily\u entry表,但当我调用api以获取daily\u entry表的所有数据时,它会发送如下响应 dataValues:{id: 1, entry_i: 1, daily_entry : 8468476, date: 23-10-2020, …} get entry_id:ƒ () {\n return this.get(attribute);\n } undefined 输出 我记录了来自

我有一个表
report\u data
,它属于
daily\u entry
表,但当我调用
api
以获取
daily\u entry
表的所有数据时,它会发送如下响应

 dataValues:{id: 1, entry_i: 1, daily_entry : 8468476, date: 23-10-2020, …}
 get entry_id:ƒ () {\n            return this.get(attribute);\n          }
 undefined
输出

我记录了来自db的数据,如下所示

 dataValues:{id: 1, entry_i: 1, daily_entry : 8468476, date: 23-10-2020, …}
 get entry_id:ƒ () {\n            return this.get(attribute);\n          }
 undefined
我检查了我的整个项目,没有像
entry\u I

API I代码如下所示

getdaily_entryById: async (req, res) => {
    sequelize.sequelize.transaction(async (t1) => {

        if (!req.params.id) {
            logger.warn(error.MANDATORY_FIELDS)
            return res.status(500).send(error.MANDATORY_FIELDS);
        }

        let data = await sequelize.daily_entry.findOne({
            where: { id: req.params.id },
            include: [
                sequelize.report_data
            ]
        });
        let result = error.OK
        result.data = data

        logger.info(result);
        return res.status(200).send(result);

    }).catch(function (err) {
        logger.warn(err)
        console.log(err)
        return res.status(500).send(error.SERVER_ERROR);
    });
}
每日项目表格模式

module.exports = function (sequelize, DataTypes) {

    const daily_entry = sequelize.define('daily_entry ', {
    user_id: {
        type: DataTypes.INTEGER(),
        allowNull: true
    },
    date: {
        type: DataTypes.STRING,
        allowNull: true
    },
    report_status: {
        type: DataTypes.STRING,
        allowNull: true
    },
    high_close: {
        type: DataTypes.DOUBLE(),
        allowNull: true
    },
    high_open: {
        type: DataTypes.DOUBLE(),
        allowNull: true
    },
    low_close: {
        type: DataTypes.DOUBLE(),
        allowNull: true
    },
    low_open: {
        type: DataTypes.DOUBLE(),
        allowNull: true
    },
    is_active: {
        type: DataTypes.BOOLEAN,
        allowNull: true
    }
 });

 return daily_entry 

};
报告数据表格模式

module.exports = function (sequelize, DataTypes) {

const report_data= sequelize.define('report_data', {
    daily_entry : {
        type: DataTypes.INTEGER(),
        allowNull: true
    },
    Date: {
        type: DataTypes.INTEGER(),
        allowNull: true
    },
    report_document_id: {
        type: DataTypes.TEXT,
        allowNull: true
    }
 },
    {
        tableName: 'report_data'
    });
 return report_data
};

那么,我哪里做错了?为什么我将
条目作为外键

尝试将表名更改为CamelCase,然后再试一次


我知道这应该是注释,但现在我没有评论的特权,如果您使用
psql name\u of_db
跳入数据库本身,并执行
\d每日\u输入
\d报告_数据
,以便我们可以确认数据库中的模式?如果您从数据库中单独提取这些记录(非连接)数据键是否正确?您的外键显示的是
foreignKey:'entry\u id
,但架构显示的是
daily\u entry
,这似乎是错误的。我已尝试更改achema
report\u data的名称,并成功获得了结果。但我想使用report_DataThank@GregoryOstermayr为您提供宝贵的时间
module.exports = function (sequelize, DataTypes) {

    const daily_entry = sequelize.define('daily_entry ', {
    user_id: {
        type: DataTypes.INTEGER(),
        allowNull: true
    },
    date: {
        type: DataTypes.STRING,
        allowNull: true
    },
    report_status: {
        type: DataTypes.STRING,
        allowNull: true
    },
    high_close: {
        type: DataTypes.DOUBLE(),
        allowNull: true
    },
    high_open: {
        type: DataTypes.DOUBLE(),
        allowNull: true
    },
    low_close: {
        type: DataTypes.DOUBLE(),
        allowNull: true
    },
    low_open: {
        type: DataTypes.DOUBLE(),
        allowNull: true
    },
    is_active: {
        type: DataTypes.BOOLEAN,
        allowNull: true
    }
 });

 return daily_entry 

};
module.exports = function (sequelize, DataTypes) {

const report_data= sequelize.define('report_data', {
    daily_entry : {
        type: DataTypes.INTEGER(),
        allowNull: true
    },
    Date: {
        type: DataTypes.INTEGER(),
        allowNull: true
    },
    report_document_id: {
        type: DataTypes.TEXT,
        allowNull: true
    }
 },
    {
        tableName: 'report_data'
    });
 return report_data
};