I'm trying to push my DB with sequelize, but it doesn't works, i have this schema for DB
module.exports = (sequelize, DataTypes) => {
const Problems = sequelize.define("Posts", {
theme: {
type: DataTypes.STRING,
allowNull: false,
},
name: {
type: DataTypes.STRING,
allowNull: false,
},
condition: {
type: DataTypes.STRING,
allowNull: false,
},
answer: {
type: DataTypes.STRING,
allowNull: false,
},
answer2: {
type: DataTypes.STRING,
allowNull: true,
},
answer3: {
type: DataTypes.STRING,
allowNull: true,
},
username: {
type: DataTypes.STRING,
allowNull: false,
},
});
return Problems;
};
and in my connection file:
const express = require("express");
const router = express.Router();
const Problems = require('../models/Problems');
router.get("/", async (req, res) => {
res.send("hi")
});
router.post("/", async (req, res) => {
const problem = req.body;
await Problems.create(problem);
res.json(problem);
});
module.exports = router;
So, when i Try to post data with Insomnia ai've got the next error: Cannot read property 'create' of undefined
Please try the following;
const Problems = require('../models/Problems').Posts;