The function Sequelize.create() does not exist

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

Answer №1

Here are some steps you can take:

const Issues = require('../models/Problems').Posts;

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Encountering a problem with ActiveRecord::Associations::CollectionProxy

After using the modal, I encountered an issue with my second modal in Rails. The code for this is as follows: class School < ActiveRecord::Base has_many :standards In my attempt to extract a list of school subjects in the view, I used the following ...

Using ObjectIds in HTTP requests with MongoDB

I'm currently facing some challenges with understanding how HTTP request queries function. My goal is to send an array of ObjectIDs in a http request query to my express server. const query = { ids: [ new ObjectID(), new ObjectID(), ], }; ...

What is the process for clearing cache in inversifyJS?

In my simple application, I am using express server along with TypeScript. Initially, I can successfully reach my endpoint, but after updating the model, the old data persists. I have attempted the suggested approach mentioned here: How to disable webpage ...

Spontaneous Link with JQuery and Colorbox

Just to clarify, I have no programming experience so please explain everything in simple terms. I am currently using a .js script within SharePoint and it's working perfectly! <!DOCTYPE html> <html> <head> <meta charset= ...

Retrieve data from the redux store within the components nested under redux-simple-router

I am currently working on finding a way to access the redux store within a route in order to dispatch actions directly from that location. Below is an example of how my main Component is structured: class App extends Component { render() { return ( ...

What purpose does the .set() function serve in Node.js with Express?

As I delve into learning Node syntax, there's this particular code snippet that has caught my curiosity. Can you shed some light on its purpose? server.set('views', __dirname); ...

How to Eliminate the Border on the Final Item within a React List

Hi everyone, I need help with removing the border of the last item in an unordered list when the list reaches a certain size. I initially tried this: document.querySelector('.employee-list-item:last-child').style.border = "none"; However, I enc ...

Need help triggering Ajax code upon clicking a link?

Can someone help me find the issue with my script? Below is the code snippet: <script> $(".icross").click(function(e){ e.preventDefault(); var obj = $(this); $.ajax({ type: "GET", url: "supprimer.php", data: 'id=&a ...

stopPropagation() halts the propagation in the opposite direction

I encountered an issue while attempting to create a non-clickable div. While it does stop propagation, it doesn't prevent what should be stopped and allows things that shouldn't be clickable. js //screen has set stopPropagation $("#smokeScree ...

Convert Time: segment time devoted to the main content from the time dedicated to advertisements

Can anyone assist me with solving a math problem? Let's consider two lists or arrays: Content Array 0-50 = C1 50-100 = C2 AD Array 10-20 = A1 30-60 = A2 80-140 = A3 The desired output should be: 0-10 = C1 10-20 = A1 20-30 = C1 30-60 = A2 60-80 = C ...

I would like to request information regarding PHP

I am attempting to retrieve information from a PHP file and insert HTML code into the <div id="1"..., but there are no errors showing and nothing is being inserted into the div. Could the issue be with the AJAX code or is it a problem within the HTML st ...

How can I choose a mesh in three.js that is not part of the loader?

I'm facing a challenge with changing the material of a mesh using three.js's mesh loader. Although I can easily change the material within the loader, I encounter an issue where I can no longer access it from an external function. It seems to be ...

Combine two queries in JavaScript by using arrays

I have a unique challenge where I can only post once every 90 minutes, so here's my double question. First up, I need to create a function that can replace a specific character in a string with a space. //====================== EXAMPLE ============= ...

Inquiry to an outside domain

I need to send a request to an external domain, ensuring that the parameter is correctly sent to a PHP file on the external server. However, I'm facing an issue where "request.responseText" always returns empty. Any assistance in this matter would be ...

What is the best way to set up an on-change listener for material-ui's <CustomInput...>?

I'm currently utilizing the React dashboard created by Creative Tim. I have a question regarding how to set up an onChange listener for a Here is the code snippet for the custom input class: import React from "react"; import classNames from "classna ...

I have successfully deployed my node and express app locally, but unfortunately, I encounter issues when trying to deploy it to Heroku

Apologies if this seems like a simple problem. I'm fairly new to working with Node + Express and still trying to grasp some key concepts! I've encountered an issue with my Node + Express app where it runs locally without any problems, but when I ...

Is it possible to set a different default page index other than 0 in a material table using reactjs?

I have noticed that the default page index in the material table is set to '0', but the API I am currently using begins with a page index of '1'. Is there a way to adjust the default page index of the table to match that of the API? ...

The ng-model failed to display the updated value until a click was made somewhere on the page

I am struggling with displaying the correct value of an ngModel variable defined in my controller. Despite changing to the correct value in the console, it doesn't update on the page until I click somewhere else or hit the update button again. Here&a ...

Here's a unique version: "Strategies for effectively closing a modal when moving to a

I'm currently working with react-router-dom and material UI modal, and I am looking for a way to automatically hide the modal whenever the user navigates to another page. Here is my App component: const App = () => ( <BrowserRouter> &l ...

I am looking to create a route with parameters in Next.js, as well as without any parameters

I am working on a NEXTJS project and utilizing SSR for data fetching. However, I am trying to implement the following scenario: When users land on the "/" route, they should be presented with a random product detail page. But if they search for a specific ...