The Sequelize database is experiencing an issue that is not providing an error message

My journey with PostgreSQL begins as I delve into creating a REST API using Sequelize for PostgreSQL, Express.js, and Node.js. One of the challenges I encountered was setting up a user system where each user can have multiple parcels associated with them. However, when trying to create a new parcel linked to a user through their userId, I kept running into a vague database error in Sequelize without any clear message, only indicating 'checkInsertTarget' routine being the issue.

Error Encountered

{
    "name": "SequelizeDatabaseError",
    "parent": {
        "name": "error",
        "length": 190,
        "severity": "ERROR",
        "code": "42703",
        "position": "48",
        "file": "d:\\pginstaller.auto\\postgres.windows-x64\\src\\backend\\parser\\parse_target.c",
        "line": "1033",
        "routine": "checkInsertTargets",
        "sql": "INSERT INTO \"Parcels\" (\"id\",\"name\",\"delivered\",\"presentLoc\",\"destination\",\"description\",\"createdAt\",\"updatedAt\",\"userId\") VALUES (DEFAULT,'Shoe',false,'Onitsha','ESUT','black shoe, size 34','2018-11-25 15:48:13.100 +00:00','2018-11-25 15:48:13.100 +00:00','3') RETURNING *;"
    },
    "original": {
        "name": "error",
        "length": 190,
        "severity": "ERROR",
        "code": "42703",
        "position": "48",
        "file": "d:\\pginstaller.auto\\postgres.windows-x64\\src\\backend\\parser\\parse_target.c",
        "line": "1033",
        "routine": "checkInsertTargets",
        "sql": "INSERT INTO \"Parcels\" (\"id\",\"name\",\"delivered\",\"presentLoc\",\"destination\",\"description\",\"createdAt\",\"updatedAt\",\"userId\") VALUES (DEFAULT,'Shoe',false,'Onitsha','ESUT','black shoe, size 34','2018-11-25 15:48:13.100 +00:00','2018-11-25 15:48:13.100 +00:00','3') RETURNING *;"
    },
    "sql": "INSERT INTO \"Parcels\" (\"id\",\"name\",\"delivered\",\"presentLoc\",\"destination\",\"description\",\"createdAt\",\"updatedAt\",\"userId\") VALUES (DEFAULT,'Shoe',false,'Onitsha','ESUT','black shoe, size 34','2018-11-25 15:48:13.100 +00:00','2018-11-25 15:48:13.100 +00:00','3') RETURNING *;"
}

Parcel Migration Setup

'use strict';
    module.exports = {
      up: (queryInterface, Sequelize) => {
        return queryInterface.createTable('Parcels', {
          id: {
            allowNull: false,
            autoIncrement: true,
            primaryKey: true,
            type: Sequelize.INTEGER
          },
          name: {
            type: Sequelize.STRING
          },
          delivered: {
            type: Sequelize.BOOLEAN
          },
          presentLoc: {
            type: Sequelize.STRING
          },
          destination: {
            type: Sequelize.STRING
          },
          description: {
            type: Sequelize.STRING
          },
          createdAt: {
            allowNull: false,
            type: Sequelize.DATE
          },
          updatedAt: {
            allowNull: false,
            type: Sequelize.DATE
          },
          userId: {
            type: Sequelize.INTEGER,
            onDelete: 'CASCADE',
            references: {
              model: 'Users',
              key: 'id',
              as: 'userId',
            }
          }
        });
      },
      down: (queryInterface, Sequelize) => {
        return queryInterface.dropTable('Parcels');
      }
    };

Parcel Model Structure

'use strict';
module.exports = (sequelize, DataTypes) => {
  const Parcel = sequelize.define('Parcel', {
    name: {
      type: DataTypes.STRING,
      allowNull: false
    },
    delivered: {
      type: DataTypes.BOOLEAN,
      defaultValue: false
    },
    presentLoc: {
      type: DataTypes.STRING,
      allowNull: false
    },
    destination: {
      type: DataTypes.STRING,
      allowNull: false
    },
    description: DataTypes.STRING,
  }, {});

  Parcel.associate = (models) => {
    Parcel.belongsTo(models.User, {
      foreignKey: 'userId',
      onDelete: 'CASCADE'
    })
  };
  return Parcel;
};

Parcel Controller Logic

const Parcel = require('../models').Parcel;
const joiSchema = require('../joischema/parcelSchema');
const validator = require('../joischema/validator');

module.exports = {
    create(req, res) {
        const data = {
            name: req.body.name,
            description: req.body.description,
            destination: req.body.destination,
            presentLoc: req.body.presentLoc,
            userId: req.params.userId,
        };
        const valid = validator.isValid(req, res, joiSchema, data);
        if (valid != null){
            res.status(500).send(valid);
        }else{
            return Parcel
                .create(data)
                .then(parcel => res.status(201).send(parcel))
                .catch(error => res.status(400).send(error));
            }
    }

Answer №1

After reviewing the database, I noticed a column that I believed had been deleted. To rectify this, I executed the commands sequelize db:migrate:undo followed by sequelize db:migrate in order to implement the necessary changes, specifically removing the unwanted column.

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

Unable to add any packages using Node.js

As a newcomer to Ionic, Cordova, and Node.js, I am facing an issue with Node.js that I need help with. The project I received from a colleague involves Ionic and Cordova. While the app is up and running, customizing the design for a specific customer has ...

Can new content be incorporated into an existing JSON file using HTML input and the fs.writeFile function?

I recently started learning about node.js and decided to create a comment section that is rendered by the node.js server. I successfully passed the value from a json file into an ejs file, which rendered fine. Now, I have added an input field and submit b ...

Having trouble launching the Socket.io Chat Demo? Encounter an issue with the error message at ..//

Hello, I am a novice in the world of programming and recently attempted to run the socket.io chat demo. Unfortunately, I encountered an error message at line 5 stating that it cannot find ('../..'). Can someone please shed some light on why this ...

What is prompting socket.io to generate an additional 'sid' cookie with a distinct path?

Currently, I'm encountering an issue with my project where express and socket.io are creating two separate "sid" cookies with different paths ("/" and "/socket.io"). This behavior is not what I expected as I want to share the same cookie/session betwe ...

Prevent the addition of a backslash by default in the fs.createWriteStream function in Node.js

Currently, I am experimenting with the ytdl-core library to download YouTube videos and it's working well for me. However, I encountered an issue when trying to download a video with a single quote in the title, causing an error from the fs library. ...

Permission Error: Client has been denied access to the requested data in the Firebase Database

I have a database named users set up on Firebase. I've configured the following rule to allow read and write access: rules_version = '2'; service cloud.firestore { match /databases/{database}/documents { allow read, write: if true; ...

node js retrieves information from the request body

Hey there! I'm diving into the world of Node.js and JavaScript, but I've hit a roadblock. I'm trying to fetch data from a URL using node-fetch, then parse it as JSON. However, I keep running into the issue of getting 'undefined' in ...

Notification from the background has been received and parameters have been restored

Sending a post request from "angular->port 4200" to "expressjs server->port 8000". Referencing this example: https://github.com/kuncevic/angular-httpclient-examples/blob/master/client/src/app/app.component.ts Encountering two errors: 1) Undefined respon ...

What are the available methods for incorporating node.js dependencies into a Python package?

At the moment, I am working with a few Python packages that are not yet published and are used locally. For development purposes, I install these packages on Linux using a Bash script into an activated virtual environment. Here's how I do it: cd /roo ...

the .text() method from Cheerio results in a blank string

I am attempting to extract data from this HTML using Node.js and Cheerio in order to retrieve the number 72 from within a span tag. However, despite specifying the selector, it returns an empty string. In this scenario, I specifically need to target the n ...

Exploring Nested Queries in MongoDB

Here is the schema I am working with: var playerScheme = new Schema({ _id:String, score:Number } I am attempting to determine the rank of each player by counting the number of users who have more points than a specific user, let's call t ...

Error caused by improper syntax in NPM script containing parentheses

I'm encountering an issue with a specific NPM script in my package.json file. Here's the script causing trouble: { "scripts": { "lint": "tslint -c tslint.json src/**/**?(.test).ts?(x)" } } Upon running npm run lint, I receive the follo ...

How can one keep object values constant or unchanging in JavaScript?

Here is a simple example where I need to clarify my requirement. I want to ensure that the values of object a are not changed after assigning it to constant b and modifying its values. I want the console to display the original values of object a, not the ...

Retrieve dynamic JSON data in a NodeJS RESTful API through fetching

Currently, I am in the process of retrieving JSON data from an API using node-fetch within my Express application. So far, I have been successful in fetching data by entering the absolute URL. However, my goal is to fetch data that is entered in req.body l ...

Is it possible to integrate third-party plugins with Materialize CSS?

I am interested in incorporating the tooltip-balloon feature from https://github.com/goisneto/Tooltip-Balloon into my node_modules for materializecss. I need guidance on the most effective way to achieve this using NPM. ...

When attempting to parse a file name using a regular expression in TypeScript (or even plain Node.js), the unexpected outcome is a

Looking to extract language information from a filename? Check out this simple construct: The structure of my language.ts model is as follows: export interface Language { language?: string; region?: string; } The function designed for parsing the fi ...

The NPM start script executes successfully in a local shell, but encounters errors when run within a Docker container

I have a Node application with three separate Node servers running using pm2 start. To start all three servers concurrently, I am using concurrently in my package.json file: "scripts": { ... "start-all": "concurrently \" pm2 start ./dist/foo. ...

Twilio notifies users of call completion status for every call made

I've been working on setting up Status Callbacks for calls in nodeJS. I configured the 'CALL STATUS CHANGES' in phone number settings to send a POST request to my node, but it seems that Twilio is sending call status "completed" for all call ...

Error occurred with Prisma prepared statement during execution of basic query

Technology: Node.js Database: MySQL ORM: Prisma I'm encountering a problem while trying to execute this query in Prisma. My database currently has around 100,000 books. However, when I run the command below, I receive an error: Error occurred durin ...

What is the process for transferring an image from a cloud function request to the vision API?

Just set up a Google Cloud Function with an HTTP endpoint. I want to pass an image to this endpoint and have it sent all the way to the Vision API (which is already set up) and then receive the response back. So, in essence: image in POST request -> C ...