gpt4 book ai didi

javascript - 我怎样才能解决 "Cannot read property ' 定义的未定义”?

转载 作者:行者123 更新时间:2023-12-03 22:22:41 24 4
gpt4 key购买 nike

在我的项目中,我使用 sequelize 为 Postgresql 中存在的数据定义了模型。我收到 Uncaught Error: Cannot read property 'define' of undefined TypeError: Cannot read property 'define' of undefined
我尝试添加 var Sequelize = require('sequelize'); 但这没有用
我该如何解决这个错误?
楷模

module.exports = {
Customer_data: (sequelize, DataTypes) => {
const Customer_data = sequelize.define('Customer_data', {
termkey: {
type: DataTypes.NUMBER,
allowNull: false,
primaryKey: true
},

}

return Customer_data;
}}
正在路由文件中调用 Customer_data
路由.js 文件
const NewFile= require("../db/newFile"),
newFile= new NewFile(config.db.release.dataset);

const { sequelize } = newFile;
const Sequelize = require('sequelize');
const { Customer_data} = require('../db/Models');
const customer_data= Customer_data(sequelize, Sequelize);


新文件.js
const { db: { release: { color: color1, color2} }, sequelize: conf }
= require("config"),
{ Sequelize, Op, NumberTypes } = require("sequelize");

module.exports = NewFile;
class NewFile{
//code
}

最佳答案

您可能应该通过在构造函数中传递数据库、用户、密码、选项来创建一个新的 sequelize 对象。

constructor(conn){
sequelize = new Sequelize(conn.db,conn.user,conn.password,conn.options);
}

关于javascript - 我怎样才能解决 "Cannot read property ' 定义的未定义”?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66070112/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com