My attempts to push my DB with sequelize are not working, even though I have set up this schema for the 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;
};
In my connection file, I have the following code:
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;
However, when I try to post data using Insomnia, I encounter the error: Cannot read property 'create' of undefined